class OpenSSL::Engine
Diese Klasse ist der Zugriff auf die ENGINE kryptografische Modulimplementierung von OpenSSL.
Siehe auch: www.openssl.org/docs/crypto/engine.html
Öffentliche Klassenmethoden
Source
static VALUE
ossl_engine_s_by_id(VALUE klass, VALUE id)
{
ENGINE *e;
VALUE obj;
StringValueCStr(id);
ossl_engine_s_load(1, &id, klass);
obj = NewEngine(klass);
if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
ossl_raise(eEngineError, NULL);
SetEngine(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);
ossl_clear_error();
return obj;
}
Ruft die Engine ab, die durch die id String spezifiziert ist.
OpenSSL::Engine.by_id("openssl")
=> #<OpenSSL::Engine id="openssl" name="Software engine support">
Siehe OpenSSL::Engine.engines für die aktuell geladenen Engines.
Source
static VALUE
ossl_engine_s_cleanup(VALUE self)
{
return Qnil;
}
Das Aufräumen ist nur notwendig, wenn Engines über OpenSSL::Engine.load geladen werden. Es wird jedoch empfohlen, vor dem Beenden aufzuräumen.
Beachten Sie, dass dies nur in OpenSSL < 1.1.0 benötigt wird und funktioniert.
Source
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)){
obj = NewEngine(klass);
/* Need a ref count of two here because of ENGINE_free being
* called internally by OpenSSL when moving to the next ENGINE
* and by us when releasing the ENGINE reference */
ENGINE_up_ref(e);
SetEngine(obj, e);
rb_ary_push(ary, obj);
}
return ary;
}
Gibt ein Array der aktuell geladenen Engines zurück.
Source
static VALUE
ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
{
VALUE name;
rb_scan_args(argc, argv, "01", &name);
if(NIL_P(name)){
ENGINE_load_builtin_engines();
return Qtrue;
}
StringValueCStr(name);
OSSL_ENGINE_LOAD_IF_MATCH(dynamic, DYNAMIC);
OSSL_ENGINE_LOAD_IF_MATCH(padlock, PADLOCK);
OSSL_ENGINE_LOAD_IF_MATCH(capi, CAPI);
OSSL_ENGINE_LOAD_IF_MATCH(cryptodev, CRYPTODEV);
OSSL_ENGINE_LOAD_IF_MATCH(openssl, OPENSSL);
rb_warning("no such builtin loader for `%"PRIsVALUE"'", name);
return Qnil;
}
Diese Methode lädt Engines. Wenn name nil ist, werden alle integrierten Engines geladen. Andernfalls wird der gegebene name als String geladen, falls für Ihre Laufzeitumgebung verfügbar, und gibt true zurück. Wenn name nicht gefunden wird, wird nil zurückgegeben.
Öffentliche Instanzmethoden
Source
static VALUE
ossl_engine_get_cipher(VALUE self, VALUE name)
{
ENGINE *e;
const EVP_CIPHER *ciph, *tmp;
int nid;
tmp = EVP_get_cipherbyname(StringValueCStr(name));
if(!tmp) ossl_raise(eEngineError, "no such cipher `%"PRIsVALUE"'", name);
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);
}
Gibt eine neue Instanz von OpenSSL::Cipher mit dem Namen name zurück, falls dieser in dieser Engine verfügbar ist.
Es wird ein EngineError ausgelöst, wenn der Cipher nicht verfügbar ist.
e = OpenSSL::Engine.by_id("openssl")
=> #<OpenSSL::Engine id="openssl" name="Software engine support">
e.cipher("RC4")
=> #<OpenSSL::Cipher:0x007fc5cacc3048>
Source
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;
}
Gibt ein Array von Befehlsdefinitionen für die aktuelle Engine zurück
Source
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);
ret = ENGINE_ctrl_cmd_string(e, StringValueCStr(cmd),
NIL_P(val) ? NULL : StringValueCStr(val), 0);
if (!ret) ossl_raise(eEngineError, NULL);
return self;
}
Sendet den gegebenen command an diese Engine.
Löst einen EngineError aus, wenn der Befehl fehlschlägt.
Source
static VALUE
ossl_engine_get_digest(VALUE self, VALUE name)
{
ENGINE *e;
const EVP_MD *md, *tmp;
int nid;
tmp = EVP_get_digestbyname(StringValueCStr(name));
if(!tmp) ossl_raise(eEngineError, "no such digest `%"PRIsVALUE"'", name);
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);
}
Gibt eine neue Instanz von OpenSSL::Digest mit dem Namen name zurück.
Löst einen EngineError aus, wenn der Digest nicht verfügbar ist.
e = OpenSSL::Engine.by_id("openssl") #=> #<OpenSSL::Engine id="openssl" name="Software engine support"> e.digest("SHA1") #=> #<OpenSSL::Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709> e.digest("zomg") #=> OpenSSL::Engine::EngineError: no such digest `zomg'
Source
static VALUE
ossl_engine_finish(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
if(!ENGINE_finish(e)) ossl_raise(eEngineError, NULL);
return Qnil;
}
Gibt alle internen strukturellen Referenzen für diese Engine frei.
Kann einen EngineError auslösen, wenn die Engine nicht verfügbar ist
Source
static VALUE
ossl_engine_get_id(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
return rb_str_new2(ENGINE_get_id(e));
}
Ruft die ID für diese Engine ab.
OpenSSL::Engine.load OpenSSL::Engine.engines #=> [#<OpenSSL::Engine#>, ...] OpenSSL::Engine.engines.first.id #=> "rsax"
Source
static VALUE
ossl_engine_inspect(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
return rb_sprintf("#<%"PRIsVALUE" id=\"%s\" name=\"%s\">",
rb_obj_class(self), ENGINE_get_id(e), ENGINE_get_name(e));
}
Gibt diese Engine schön formatiert aus.
Source
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 : StringValueCStr(id);
sdata = NIL_P(data) ? NULL : StringValueCStr(data);
GetEngine(self, e);
pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
if (!pkey) ossl_raise(eEngineError, NULL);
obj = ossl_pkey_wrap(pkey);
OSSL_PKEY_SET_PRIVATE(obj);
return obj;
}
Lädt den gegebenen privaten Schlüssel, identifiziert durch id und data.
Ein EngineError wird ausgelöst, wenn der OpenSSL::PKey nicht verfügbar ist.
Source
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 : StringValueCStr(id);
sdata = NIL_P(data) ? NULL : StringValueCStr(data);
GetEngine(self, e);
pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
if (!pkey) ossl_raise(eEngineError, NULL);
return ossl_pkey_wrap(pkey);
}
Lädt den gegebenen öffentlichen Schlüssel, identifiziert durch id und data.
Ein EngineError wird ausgelöst, wenn der OpenSSL::PKey nicht verfügbar ist.
Source
static VALUE
ossl_engine_get_name(VALUE self)
{
ENGINE *e;
GetEngine(self, e);
return rb_str_new2(ENGINE_get_name(e));
}
Ruft den beschreibenden Namen für diese Engine ab.
OpenSSL::Engine.load OpenSSL::Engine.engines #=> [#<OpenSSL::Engine#>, ...] OpenSSL::Engine.engines.first.name #=> "RSAX engine support"
Source
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;
}
Setzt die Standardwerte für diese Engine mit dem gegebenen flag.
Diese Flags werden verwendet, um Kombinationen von Algorithmenmethoden zu steuern.
flag kann einer der folgenden sein, weitere Flags sind je nach Betriebssystem verfügbar.
- Alle Flags
-
0xFFFF
- Keine Flags
-
0x0000
Siehe auch <openssl/engine.h>