Class: OpenSSL::Engine
- Inherits:
-
Object
- Object
- OpenSSL::Engine
- Defined in:
- ext/rubysl/openssl/ossl_engine.c
Defined Under Namespace
Classes: EngineError
Class Method Summary collapse
Instance Method Summary collapse
- #cipher(name) ⇒ Object
- #cmds ⇒ Object
- #ctrl_cmd(*args) ⇒ Object
- #digest(name) ⇒ Object
- #finish ⇒ Object
- #id ⇒ Object
- #inspect ⇒ Object
- #load_private_key(*args) ⇒ Object
- #load_public_key(*args) ⇒ Object
- #name ⇒ Object
- #set_default(flag) ⇒ Object
Class Method Details
.by_id(id) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 125
static VALUE
ossl_engine_s_by_id(VALUE klass, VALUE id)
{
ENGINE *e;
VALUE obj;
StringValue(id);
ossl_engine_s_load(1, &id, klass);
if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
ossl_raise(eEngineError, NULL);
WrapEngine(klass, obj, e);
if(rb_block_given_p()) rb_yield(obj);
if(!ENGINE_init(e))
ossl_raise(eEngineError, NULL);
ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
0, NULL, (void(*)(void))ossl_pem_passwd_cb);
ERR_clear_error();
return obj;
}
|
.cleanup ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 101
static VALUE
ossl_engine_s_cleanup(VALUE self)
{
#if defined(HAVE_ENGINE_CLEANUP)
ENGINE_cleanup();
#endif
return Qnil;
}
|
.engines ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 110
static VALUE
ossl_engine_s_engines(VALUE klass)
{
ENGINE *e;
VALUE ary, obj;
ary = rb_ary_new();
for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
WrapEngine(klass, obj, e);
rb_ary_push(ary, obj);
}
return ary;
}
|
.load(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 49
static VALUE
ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
{
#if !defined(HAVE_ENGINE_LOAD_BUILTIN_ENGINES)
return Qnil;
#else
VALUE name;
rb_scan_args(argc, argv, "01", &name);
if(NIL_P(name)){
ENGINE_load_builtin_engines();
return Qtrue;
}
StringValue(name);
#ifndef OPENSSL_NO_STATIC_ENGINE
#if HAVE_ENGINE_LOAD_DYNAMIC
OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
#endif
#if HAVE_ENGINE_LOAD_CSWIFT
OSSL_ENGINE_LOAD_IF_MATCH(cswift);
#endif
#if HAVE_ENGINE_LOAD_CHIL
OSSL_ENGINE_LOAD_IF_MATCH(chil);
#endif
#if HAVE_ENGINE_LOAD_ATALLA
OSSL_ENGINE_LOAD_IF_MATCH(atalla);
#endif
#if HAVE_ENGINE_LOAD_NURON
OSSL_ENGINE_LOAD_IF_MATCH(nuron);
#endif
#if HAVE_ENGINE_LOAD_UBSEC
OSSL_ENGINE_LOAD_IF_MATCH(ubsec);
#endif
#if HAVE_ENGINE_LOAD_AEP
OSSL_ENGINE_LOAD_IF_MATCH(aep);
#endif
#if HAVE_ENGINE_LOAD_SUREWARE
OSSL_ENGINE_LOAD_IF_MATCH(sureware);
#endif
#if HAVE_ENGINE_LOAD_4758CCA
OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
#endif
#endif
#ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO
OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
#endif
OSSL_ENGINE_LOAD_IF_MATCH(openssl);
rb_warning("no such builtin loader for `%s'", RSTRING_PTR(name));
return Qnil;
#endif /* HAVE_ENGINE_LOAD_BUILTIN_ENGINES */
}
|
Instance Method Details
#cipher(name) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 187
static VALUE
ossl_engine_get_cipher(VALUE self, VALUE name)
{
#if defined(HAVE_ENGINE_GET_CIPHER)
ENGINE *e;
const EVP_CIPHER *ciph, *tmp;
char *s;
int nid;
s = StringValuePtr(name);
tmp = EVP_get_cipherbyname(s);
if(!tmp) ossl_raise(eEngineError, "no such cipher `%s'", s);
nid = EVP_CIPHER_nid(tmp);
GetEngine(self, e);
ciph = ENGINE_get_cipher(e, nid);
if(!ciph) ossl_raise(eEngineError, NULL);
return ossl_cipher_new(ciph);
#else
rb_notimplement();
#endif
}
|
#cmds ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 321
static VALUE
ossl_engine_get_cmds(VALUE self)
{
ENGINE *e;
const ENGINE_CMD_DEFN *defn, *p;
VALUE ary, tmp;
GetEngine(self, e);
ary = rb_ary_new();
if ((defn = ENGINE_get_cmd_defns(e)) != NULL){
for (p = defn; p->cmd_num > 0; p++){
tmp = rb_ary_new();
rb_ary_push(tmp, rb_str_new2(p->cmd_name));
rb_ary_push(tmp, rb_str_new2(p->cmd_desc));
rb_ary_push(tmp, ossl_engine_cmd_flag_to_name(p->cmd_flags));
rb_ary_push(ary, tmp);
}
}
return ary;
}
|
#ctrl_cmd(*args) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 291
static VALUE
ossl_engine_ctrl_cmd(int argc, VALUE *argv, VALUE self)
{
ENGINE *e;
VALUE cmd, val;
int ret;
GetEngine(self, e);
rb_scan_args(argc, argv, "11", &cmd, &val);
StringValue(cmd);
if (!NIL_P(val)) StringValue(val);
ret = ENGINE_ctrl_cmd_string(e, RSTRING_PTR(cmd),
NIL_P(val) ? NULL : RSTRING_PTR(val), 0);
if (!ret) ossl_raise(eEngineError, NULL);
return self;
}
|
#digest(name) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 210
static VALUE
ossl_engine_get_digest(VALUE self, VALUE name)
{
#if defined(HAVE_ENGINE_GET_DIGEST)
ENGINE *e;
const EVP_MD *md, *tmp;
char *s;
int nid;
s = StringValuePtr(name);
tmp = EVP_get_digestbyname(s);
if(!tmp) ossl_raise(eEngineError, "no such digest `%s'", s);
nid = EVP_MD_nid(tmp);
GetEngine(self, e);
md = ENGINE_get_digest(e, nid);
if(!md) ossl_raise(eEngineError, NULL);
return ossl_digest_new(md);
#else
rb_notimplement();
#endif
}
|
#finish ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 176
static VALUE
ossl_engine_finish(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
if(!ENGINE_finish(e)) ossl_raise(eEngineError, NULL);
return Qnil;
}
|
#id ⇒ Object
160 161 162 163 164 165 166 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 160
static VALUE
ossl_engine_get_id(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
return rb_str_new2(ENGINE_get_id(e));
}
|
#inspect ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 343
static VALUE
ossl_engine_inspect(VALUE self)
{
VALUE str;
const char *cname = rb_class2name(rb_obj_class(self));
str = rb_str_new2("#<");
rb_str_cat2(str, cname);
rb_str_cat2(str, " id=\"");
rb_str_append(str, ossl_engine_get_id(self));
rb_str_cat2(str, "\" name=\"");
rb_str_append(str, ossl_engine_get_name(self));
rb_str_cat2(str, "\">");
return str;
}
|
#load_private_key(*args) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 233
static VALUE
ossl_engine_load_privkey(int argc, VALUE *argv, VALUE self)
{
ENGINE *e;
EVP_PKEY *pkey;
VALUE id, data, obj;
char *sid, *sdata;
rb_scan_args(argc, argv, "02", &id, &data);
sid = NIL_P(id) ? NULL : StringValuePtr(id);
sdata = NIL_P(data) ? NULL : StringValuePtr(data);
GetEngine(self, e);
#if OPENSSL_VERSION_NUMBER < 0x00907000L
pkey = ENGINE_load_private_key(e, sid, sdata);
#else
pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
#endif
if (!pkey) ossl_raise(eEngineError, NULL);
obj = ossl_pkey_new(pkey);
OSSL_PKEY_SET_PRIVATE(obj);
return obj;
}
|
#load_public_key(*args) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 257
static VALUE
ossl_engine_load_pubkey(int argc, VALUE *argv, VALUE self)
{
ENGINE *e;
EVP_PKEY *pkey;
VALUE id, data;
char *sid, *sdata;
rb_scan_args(argc, argv, "02", &id, &data);
sid = NIL_P(id) ? NULL : StringValuePtr(id);
sdata = NIL_P(data) ? NULL : StringValuePtr(data);
GetEngine(self, e);
#if OPENSSL_VERSION_NUMBER < 0x00907000L
pkey = ENGINE_load_public_key(e, sid, sdata);
#else
pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
#endif
if (!pkey) ossl_raise(eEngineError, NULL);
return ossl_pkey_new(pkey);
}
|
#name ⇒ Object
168 169 170 171 172 173 174 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 168
static VALUE
ossl_engine_get_name(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
return rb_str_new2(ENGINE_get_name(e));
}
|
#set_default(flag) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 |
# File 'ext/rubysl/openssl/ossl_engine.c', line 279
static VALUE
ossl_engine_set_default(VALUE self, VALUE flag)
{
ENGINE *e;
int f = NUM2INT(flag);
GetEngine(self, e);
ENGINE_set_default(e, f);
return Qtrue;
}
|