class OpenSSL::Config
Konfiguration für die openssl-Bibliothek.
Die Installation der openssl-Bibliothek vieler Systeme hängt von Ihrer Systemkonfiguration ab. Siehe den Wert von OpenSSL::Config::DEFAULT_CONFIG_FILE für den Speicherort der Datei für Ihren Host.
Siehe auch docs.openssl.org/master/man5/config/
Constants
- DEFAULT_CONFIG_FILE
-
Die Standard-Systemkonfigurationsdatei für
OpenSSL.
Öffentliche Klassenmethoden
Source
static VALUE
config_initialize(int argc, VALUE *argv, VALUE self)
{
CONF *conf = GetConfig(self);
VALUE filename;
/* 0-arguments call has no use-case, but is kept for compatibility */
rb_scan_args(argc, argv, "01", &filename);
rb_check_frozen(self);
if (!NIL_P(filename)) {
BIO *bio = BIO_new_file(StringValueCStr(filename), "rb");
if (!bio)
ossl_raise(eConfigError, "BIO_new_file");
config_load_bio(conf, bio); /* Consumes BIO */
}
rb_obj_freeze(self);
return self;
}
Erstellt eine Instanz von OpenSSL::Config aus dem Inhalt der durch filename angegebenen Datei.
Dies kann in Kontexten wie OpenSSL::X509::ExtensionFactory.config= verwendet werden.
Dies kann IO-Ausnahmen auslösen, abhängig vom Zugriff oder der Verfügbarkeit der Datei. Eine ConfigError-Ausnahme kann je nach Gültigkeit der konfigurierten Daten ausgelöst werden.
Source
static VALUE
config_s_parse(VALUE klass, VALUE str)
{
VALUE obj = config_s_alloc(klass);
CONF *conf = GetConfig(obj);
BIO *bio;
bio = ossl_obj2bio(&str);
config_load_bio(conf, bio); /* Consumes BIO */
rb_obj_freeze(obj);
return obj;
}
Parst einen gegebenen string als Blob, der Konfigurationen für OpenSSL enthält.
Source
static VALUE
config_s_parse_config(VALUE klass, VALUE io)
{
VALUE obj, sections, ret;
long i;
obj = config_s_parse(klass, io);
sections = config_get_sections(obj);
ret = rb_hash_new();
for (i = 0; i < RARRAY_LEN(sections); i++) {
VALUE section = rb_ary_entry(sections, i);
rb_hash_aset(ret, section, config_get_section(obj, section));
}
return ret;
}
Parst die aus io gelesenen Konfigurationsdaten und gibt den gesamten Inhalt als Hash zurück.
Öffentliche Instanzmethoden
Source
static VALUE
config_get_section(VALUE self, VALUE section)
{
CONF *conf = GetConfig(self);
STACK_OF(CONF_VALUE) *sk;
int i, entries;
VALUE hash;
hash = rb_hash_new();
StringValueCStr(section);
if (!(sk = NCONF_get_section(conf, RSTRING_PTR(section)))) {
ossl_clear_error();
return hash;
}
entries = sk_CONF_VALUE_num(sk);
for (i = 0; i < entries; i++) {
CONF_VALUE *entry = sk_CONF_VALUE_value(sk, i);
rb_hash_aset(hash, rb_str_new_cstr(entry->name),
rb_str_new_cstr(entry->value));
}
return hash;
}
Holt alle Schlüssel-Wert-Paare in einem bestimmten section aus der aktuellen Konfiguration.
Bei der folgenden geladenen Konfigurationsdatei
config = OpenSSL::Config.load('foo.cnf') #=> #<OpenSSL::Config sections=["default"]> puts config.to_s #=> [ default ] # foo=bar
Sie können einen Hash des spezifischen Abschnitts wie folgt erhalten
config['default'] #=> {"foo"=>"bar"}
Source
static VALUE
config_each(VALUE self)
{
CONF *conf = GetConfig(self);
RETURN_ENUMERATOR(self, 0, 0);
lh_doall_arg((_LHASH *)conf->data, LHASH_DOALL_ARG_FN(each_conf_value),
NULL);
return self;
}
Ruft den Abschnitt und seine Paare für die aktuelle Konfiguration ab.
config.each do |section, key, value| # ... end
Source
static VALUE
config_get_value(VALUE self, VALUE section, VALUE key)
{
CONF *conf = GetConfig(self);
const char *str, *sectionp;
StringValueCStr(section);
StringValueCStr(key);
/* For compatibility; NULL means "default". */
sectionp = RSTRING_LEN(section) ? RSTRING_PTR(section) : NULL;
str = NCONF_get_string(conf, sectionp, RSTRING_PTR(key));
if (!str) {
ossl_clear_error();
return Qnil;
}
return rb_str_new_cstr(str);
}
Holt den Wert von key aus dem gegebenen section.
Bei der folgenden geladenen Konfigurationsdatei
config = OpenSSL::Config.load('foo.cnf') #=> #<OpenSSL::Config sections=["default"]> puts config.to_s #=> [ default ] # foo=bar
Sie können einen bestimmten Wert aus der Konfiguration erhalten, wenn Sie den section und key kennen, wie hier gezeigt
config.get_value('default','foo') #=> "bar"
Source
static VALUE
config_initialize_copy(VALUE self, VALUE other)
{
CONF *conf = GetConfig(self);
VALUE str;
BIO *bio;
str = rb_funcall(other, rb_intern("to_s"), 0);
rb_check_frozen(self);
bio = ossl_obj2bio(&str);
config_load_bio(conf, bio); /* Consumes BIO */
rb_obj_freeze(self);
return self;
}
Source
static VALUE
config_inspect(VALUE self)
{
VALUE str, ary = config_get_sections(self);
const char *cname = rb_class2name(rb_obj_class(self));
str = rb_str_new_cstr("#<");
rb_str_cat_cstr(str, cname);
rb_str_cat_cstr(str, " sections=");
rb_str_append(str, rb_inspect(ary));
rb_str_cat_cstr(str, ">");
return str;
}
String-Darstellung dieses Konfigurationsobjekts, einschließlich des Klassennamens und seiner Abschnitte.
Source
static VALUE
config_get_sections(VALUE self)
{
CONF *conf = GetConfig(self);
VALUE ary;
ary = rb_ary_new();
lh_doall_arg((_LHASH *)conf->data, LHASH_DOALL_ARG_FN(get_conf_section),
&ary);
return ary;
}
Holt die Namen aller Abschnitte in der aktuellen Konfiguration.
Source
static VALUE
config_to_s(VALUE self)
{
CONF *conf = GetConfig(self);
VALUE str;
str = rb_str_new(NULL, 0);
lh_doall_arg((_LHASH *)conf->data, LHASH_DOALL_ARG_FN(dump_conf_value),
&str);
return str;
}
Gibt die parsierbare Form der aktuellen Konfiguration zurück.
Bei der folgenden geladenen Konfigurationsdatei
config = OpenSSL::Config.load('baz.cnf') #=> #<OpenSSL::Config sections=["default"]> puts config.to_s #=> [ default ] # foo=bar # baz=buz
Sie können die serialisierte Konfiguration mit to_s erhalten und sie später parsen.
serialized_config = config.to_s # much later... new_config = OpenSSL::Config.parse(serialized_config) #=> #<OpenSSL::Config sections=["default"]> puts new_config #=> [ default ] foo=bar baz=buz