summaryrefslogtreecommitdiffstats
path: root/OpenSSL/Config.html
blob: 214c6ebfa76902f34d535b44e2c96e2afea629b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::Config - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
</script>

<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

    
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Enumerable</span>
  </ul>
</div>

    
    
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-parse">::parse</a>
    <li ><a href="#method-c-parse_config">::parse_config</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-get_value">#get_value</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-sections">#sections</a>
    <li ><a href="#method-i-to_s">#to_s</a>
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-OpenSSL::Config">
  <h1 id="class-OpenSSL::Config" class="class">
    class OpenSSL::Config
  </h1>

  <section class="description">
    
<p>Configuration for the openssl library.</p>

<p>Many system’s installation of openssl library will depend on your system configuration. See the value of <a href="Config.html#DEFAULT_CONFIG_FILE"><code>OpenSSL::Config::DEFAULT_CONFIG_FILE</code></a> for the location of the file for your host.</p>

<p>See also <a href="http://www.openssl.org/docs/apps/config.html">www.openssl.org/docs/apps/config.html</a></p>

  </section>

  <section id="5Buntitled-5D" class="documentation-section">


    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
        <dt id="DEFAULT_CONFIG_FILE">DEFAULT_CONFIG_FILE
        <dd><p>The default system configuration file for <a href="../OpenSSL.html"><code>OpenSSL</code></a>.</p>
      </dl>
    </section>



     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

      <div id="method-c-new" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            new(filename) &rarr; OpenSSL::Config
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Creates an instance of <a href="Config.html"><code>OpenSSL::Config</code></a> from the content of the file specified by <em>filename</em>.</p>

<p>This can be used in contexts like <a href="X509/ExtensionFactory.html#attribute-i-config"><code>OpenSSL::X509::ExtensionFactory.config=</code></a></p>

<p>This can raise <a href="../IO.html"><code>IO</code></a> exceptions based on the access, or availability of the file. A <a href="ConfigError.html"><code>ConfigError</code></a> exception may be raised depending on the validity of the data being configured.</p>

          <div class="method-source-code" id="new-source">
            <pre>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, &quot;01&quot;, &amp;filename);
    rb_check_frozen(self);
    if (!NIL_P(filename)) {
        BIO *bio = BIO_new_file(StringValueCStr(filename), &quot;rb&quot;);
        if (!bio)
            ossl_raise(eConfigError, &quot;BIO_new_file&quot;);
        config_load_bio(conf, bio); /* Consumes BIO */
    }
    return self;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-c-parse" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            parse(string) &rarr; OpenSSL::Config
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Parses a given <em>string</em> as a blob that contains configuration for <a href="../OpenSSL.html"><code>OpenSSL</code></a>.</p>

          <div class="method-source-code" id="parse-source">
            <pre>static VALUE
config_s_parse(VALUE klass, VALUE str)
{
    VALUE obj = config_s_alloc(klass);
    CONF *conf = GetConfig(obj);
    BIO *bio;

    bio = ossl_obj2bio(&amp;str);
    config_load_bio(conf, bio); /* Consumes BIO */
    return obj;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-c-parse_config" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            parse_config(io) &rarr; hash
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Parses the configuration data read from <em>io</em> and returns the whole content as a Hash.</p>

          <div class="method-source-code" id="parse_config-source">
            <pre>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 &lt; RARRAY_LEN(sections); i++) {
        VALUE section = rb_ary_entry(sections, i);
        rb_hash_aset(ret, section, config_get_section(obj, section));
    }
    return ret;
}</pre>
          </div>
        </div>


      </div>

    </section>

     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

      <div id="method-i-5B-5D" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            config[section] &rarr; hash
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Gets all key-value pairs in a specific <em>section</em> from the current configuration.</p>

<p>Given the following configurating file being loaded:</p>

<pre class="ruby"><span class="ruby-identifier">config</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&#39;foo.cnf&#39;</span>)
  <span class="ruby-comment">#=&gt; #&lt;OpenSSL::Config sections=[&quot;default&quot;]&gt;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">config</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment">#=&gt; [ default ]</span>
  <span class="ruby-comment">#   foo=bar</span>
</pre>

<p>You can get a hash of the specific section like so:</p>

<pre class="ruby"><span class="ruby-identifier">config</span>[<span class="ruby-string">&#39;default&#39;</span>]
  <span class="ruby-comment">#=&gt; {&quot;foo&quot;=&gt;&quot;bar&quot;}</span>
</pre>

          <div class="method-source-code" id="5B-5D-source">
            <pre>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 &lt; entries; i++) {
        CONF_VALUE *entry = sk_CONF_VALUE_value(sk, i);
        rb_hash_aset(hash, rb_str_new_cstr(entry-&gt;name),
                     rb_str_new_cstr(entry-&gt;value));
    }
    return hash;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-each" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            each { |section, key, value| }
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Retrieves the section and its pairs for the current configuration.</p>

<pre class="ruby"><span class="ruby-identifier">config</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">section</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># ...</span>
<span class="ruby-keyword">end</span>
</pre>

          <div class="method-source-code" id="each-source">
            <pre>static VALUE
config_each(VALUE self)
{
    CONF *conf = GetConfig(self);

    RETURN_ENUMERATOR(self, 0, 0);

    lh_doall_arg((_LHASH *)conf-&gt;data, LHASH_DOALL_ARG_FN(each_conf_value),
                 NULL);
    return self;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-get_value" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            get_value(section, key) &rarr; string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Gets the value of <em>key</em> from the given <em>section</em>.</p>

<p>Given the following configurating file being loaded:</p>

<pre class="ruby"><span class="ruby-identifier">config</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&#39;foo.cnf&#39;</span>)
  <span class="ruby-comment">#=&gt; #&lt;OpenSSL::Config sections=[&quot;default&quot;]&gt;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">config</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment">#=&gt; [ default ]</span>
  <span class="ruby-comment">#   foo=bar</span>
</pre>

<p>You can get a specific value from the config if you know the <em>section</em> and <em>key</em> like so:</p>

<pre class="ruby"><span class="ruby-identifier">config</span>.<span class="ruby-identifier">get_value</span>(<span class="ruby-string">&#39;default&#39;</span>,<span class="ruby-string">&#39;foo&#39;</span>)
  <span class="ruby-comment">#=&gt; &quot;bar&quot;</span>
</pre>

          <div class="method-source-code" id="get_value-source">
            <pre>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 &quot;default&quot;. */
    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);
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-initialize_copy" class="method-detail ">
        <div class="method-heading">
          <span class="method-name">initialize_copy</span><span
            class="method-args">(p1)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          

          <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
config_initialize_copy(VALUE self, VALUE other)
{
    CONF *conf = GetConfig(self);
    VALUE str;
    BIO *bio;

    str = rb_funcall(other, rb_intern(&quot;to_s&quot;), 0);
    rb_check_frozen(self);
    bio = ossl_obj2bio(&amp;str);
    config_load_bio(conf, bio); /* Consumes BIO */
    return self;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-inspect" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            inspect &rarr; string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>String representation of this configuration object, including the class name and its sections.</p>

          <div class="method-source-code" id="inspect-source">
            <pre>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(&quot;#&lt;&quot;);
    rb_str_cat_cstr(str, cname);
    rb_str_cat_cstr(str, &quot; sections=&quot;);
    rb_str_append(str, rb_inspect(ary));
    rb_str_cat_cstr(str, &quot;&gt;&quot;);

    return str;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-sections" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            sections &rarr; array of string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Get the names of all sections in the current configuration.</p>

          <div class="method-source-code" id="sections-source">
            <pre>static VALUE
config_get_sections(VALUE self)
{
    CONF *conf = GetConfig(self);
    VALUE ary;

    ary = rb_ary_new();
    lh_doall_arg((_LHASH *)conf-&gt;data, LHASH_DOALL_ARG_FN(get_conf_section),
                 &amp;ary);
    return ary;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-to_s" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            to_s &rarr; string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Gets the parsable form of the current configuration.</p>

<p>Given the following configuration being created:</p>

<pre class="ruby"><span class="ruby-identifier">config</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-comment">#=&gt; #&lt;OpenSSL::Config sections=[]&gt;</span>
<span class="ruby-identifier">config</span>[<span class="ruby-string">&#39;default&#39;</span>] = {<span class="ruby-string">&quot;foo&quot;</span><span class="ruby-operator">=&gt;</span><span class="ruby-string">&quot;bar&quot;</span>,<span class="ruby-string">&quot;baz&quot;</span><span class="ruby-operator">=&gt;</span><span class="ruby-string">&quot;buz&quot;</span>}
  <span class="ruby-comment">#=&gt; {&quot;foo&quot;=&gt;&quot;bar&quot;, &quot;baz&quot;=&gt;&quot;buz&quot;}</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">config</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-comment">#=&gt; [ default ]</span>
  <span class="ruby-comment">#   foo=bar</span>
  <span class="ruby-comment">#   baz=buz</span>
</pre>

<p>You can parse get the serialized configuration using <a href="Config.html#method-i-to_s"><code>to_s</code></a> and then parse it later:</p>

<pre class="ruby"><span class="ruby-identifier">serialized_config</span> = <span class="ruby-identifier">config</span>.<span class="ruby-identifier">to_s</span>
<span class="ruby-comment"># much later...</span>
<span class="ruby-identifier">new_config</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">serialized_config</span>)
  <span class="ruby-comment">#=&gt; #&lt;OpenSSL::Config sections=[&quot;default&quot;]&gt;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">new_config</span>
  <span class="ruby-comment">#=&gt; [ default ]</span>
      <span class="ruby-identifier">foo</span>=<span class="ruby-identifier">bar</span>
      <span class="ruby-identifier">baz</span>=<span class="ruby-identifier">buz</span>
</pre>

          <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
config_to_s(VALUE self)
{
    CONF *conf = GetConfig(self);
    VALUE str;

    str = rb_str_new(NULL, 0);
    lh_doall_arg((_LHASH *)conf-&gt;data, LHASH_DOALL_ARG_FN(dump_conf_value),
                 &amp;str);
    return str;
}</pre>
          </div>
        </div>


      </div>

    </section>

  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.3.2.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>