summaryrefslogtreecommitdiffstats
path: root/OpenSSL/X509/StoreContext.html
blob: e1f06bd510ecae752da585675c184ae9bd80c080 (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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
<!DOCTYPE html>

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

<title>class OpenSSL::X509::StoreContext - 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>

    
    
    
<!-- 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-i-chain">#chain</a>
    <li ><a href="#method-i-cleanup">#cleanup</a>
    <li ><a href="#method-i-current_cert">#current_cert</a>
    <li ><a href="#method-i-current_crl">#current_crl</a>
    <li ><a href="#method-i-error">#error</a>
    <li ><a href="#method-i-error-3D">#error=</a>
    <li ><a href="#method-i-error_depth">#error_depth</a>
    <li ><a href="#method-i-error_string">#error_string</a>
    <li ><a href="#method-i-flags-3D">#flags=</a>
    <li ><a href="#method-i-purpose-3D">#purpose=</a>
    <li ><a href="#method-i-time-3D">#time=</a>
    <li ><a href="#method-i-trust-3D">#trust=</a>
    <li ><a href="#method-i-verify">#verify</a>
  </ul>
</div>

  </div>
</nav>

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

  <section class="description">
    
<p>A <a href="StoreContext.html"><code>StoreContext</code></a> is used while validating a single certificate and holds the status involved.</p>

  </section>

  <section id="5Buntitled-5D" class="documentation-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(store, cert = nil, untrusted = nil)
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Sets up a <a href="StoreContext.html"><code>StoreContext</code></a> for a verification of the X.509 certificate <em>cert</em>.</p>

          <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE store, cert, chain, t;
    X509_STORE_CTX *ctx;
    X509_STORE *x509st;
    X509 *x509 = NULL;
    STACK_OF(X509) *x509s = NULL;
    int state;

    rb_scan_args(argc, argv, &quot;12&quot;, &amp;store, &amp;cert, &amp;chain);
    GetX509StCtx(self, ctx);
    GetX509Store(store, x509st);
    if (!NIL_P(cert))
        x509 = DupX509CertPtr(cert); /* NEED TO DUP */
    if (!NIL_P(chain)) {
        x509s = ossl_protect_x509_ary2sk(chain, &amp;state);
        if (state) {
            X509_free(x509);
            rb_jump_tag(state);
        }
    }
    if (X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
        X509_free(x509);
        sk_X509_pop_free(x509s, X509_free);
        ossl_raise(eX509StoreError, &quot;X509_STORE_CTX_init&quot;);
    }
    if (!NIL_P(t = rb_iv_get(store, &quot;@time&quot;)))
        ossl_x509stctx_set_time(self, t);
    rb_iv_set(self, &quot;@verify_callback&quot;, rb_iv_get(store, &quot;@verify_callback&quot;));
    rb_iv_set(self, &quot;@cert&quot;, cert);

    return self;
}</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-chain" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            chain &rarr; nil | Array of X509::Certificate
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns the verified chain.</p>

<p>See also the man page X509_STORE_CTX_set0_verified_chain(3).</p>

          <div class="method-source-code" id="chain-source">
            <pre>static VALUE
ossl_x509stctx_get_chain(VALUE self)
{
    X509_STORE_CTX *ctx;
    const STACK_OF(X509) *chain;

    GetX509StCtx(self, ctx);
    chain = X509_STORE_CTX_get0_chain(ctx);
    if (!chain)
        return Qnil; /* Could be an empty array instead? */
    return ossl_x509_sk2ary(chain);
}</pre>
          </div>
        </div>


      </div>

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

        <div class="method-description">
          

          <div class="method-source-code" id="cleanup-source">
            <pre><span class="ruby-comment"># File lib/openssl/x509.rb, line 337</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">cleanup</span>
  <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">$VERBOSE</span>
<span class="ruby-keyword">end</span></pre>
          </div>
        </div>


      </div>

      <div id="method-i-current_cert" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            current_cert &rarr; X509::Certificate
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns the certificate which caused the error.</p>

<p>See also the man page X509_STORE_CTX_get_current_cert(3).</p>

          <div class="method-source-code" id="current_cert-source">
            <pre>static VALUE
ossl_x509stctx_get_curr_cert(VALUE self)
{
    X509_STORE_CTX *ctx;

    GetX509StCtx(self, ctx);

    return ossl_x509_new(X509_STORE_CTX_get_current_cert(ctx));
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-current_crl" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            current_crl &rarr; X509::CRL
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns the <a href="CRL.html"><code>CRL</code></a> which caused the error.</p>

<p>See also the man page X509_STORE_CTX_get_current_crl(3).</p>

          <div class="method-source-code" id="current_crl-source">
            <pre>static VALUE
ossl_x509stctx_get_curr_crl(VALUE self)
{
    X509_STORE_CTX *ctx;
    X509_CRL *crl;

    GetX509StCtx(self, ctx);
    crl = X509_STORE_CTX_get0_current_crl(ctx);
    if (!crl)
        return Qnil;

    return ossl_x509crl_new(crl);
}</pre>
          </div>
        </div>


      </div>

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

        <div class="method-description">
          <p>Returns the error code of <em>stctx</em>. This is typically called after <a href="StoreContext.html#method-i-verify"><code>verify</code></a> is done, or from the verification callback set to <a href="Store.html#method-i-verify_callback-3D"><code>OpenSSL::X509::Store#verify_callback=</code></a>.</p>

<p>See also the man page X509_STORE_CTX_get_error(3).</p>

          <div class="method-source-code" id="error-source">
            <pre>static VALUE
ossl_x509stctx_get_err(VALUE self)
{
    X509_STORE_CTX *ctx;

    GetX509StCtx(self, ctx);

    return INT2NUM(X509_STORE_CTX_get_error(ctx));
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-error-3D" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            error = error_code
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Sets the error code of <em>stctx</em>. This is used by the verification callback set to <a href="Store.html#method-i-verify_callback-3D"><code>OpenSSL::X509::Store#verify_callback=</code></a>.</p>

<p>See also the man page X509_STORE_CTX_set_error(3).</p>

          <div class="method-source-code" id="error-3D-source">
            <pre>static VALUE
ossl_x509stctx_set_error(VALUE self, VALUE err)
{
    X509_STORE_CTX *ctx;

    GetX509StCtx(self, ctx);
    X509_STORE_CTX_set_error(ctx, NUM2INT(err));

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


      </div>

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

        <div class="method-description">
          <p>Returns the depth of the chain. This is used in combination with <a href="StoreContext.html#method-i-error"><code>error</code></a>.</p>

<p>See also the man page X509_STORE_CTX_get_error_depth(3).</p>

          <div class="method-source-code" id="error_depth-source">
            <pre>static VALUE
ossl_x509stctx_get_err_depth(VALUE self)
{
    X509_STORE_CTX *ctx;

    GetX509StCtx(self, ctx);

    return INT2NUM(X509_STORE_CTX_get_error_depth(ctx));
}</pre>
          </div>
        </div>


      </div>

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

        <div class="method-description">
          <p>Returns the human readable error string corresponding to the error code retrieved by <a href="StoreContext.html#method-i-error"><code>error</code></a>.</p>

<p>See also the man page X509_verify_cert_error_string(3).</p>

          <div class="method-source-code" id="error_string-source">
            <pre>static VALUE
ossl_x509stctx_get_err_string(VALUE self)
{
    X509_STORE_CTX *ctx;
    long err;

    GetX509StCtx(self, ctx);
    err = X509_STORE_CTX_get_error(ctx);

    return rb_str_new2(X509_verify_cert_error_string(err));
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-flags-3D" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            flags = flags
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Sets the verification flags to the context. This overrides the default value set by <a href="Store.html#method-i-flags-3D"><code>Store#flags=</code></a>.</p>

<p>See also the man page X509_VERIFY_PARAM_set_flags(3).</p>

          <div class="method-source-code" id="flags-3D-source">
            <pre>static VALUE
ossl_x509stctx_set_flags(VALUE self, VALUE flags)
{
    X509_STORE_CTX *store;
    long f = NUM2LONG(flags);

    GetX509StCtx(self, store);
    X509_STORE_CTX_set_flags(store, f);

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


      </div>

      <div id="method-i-purpose-3D" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            purpose = purpose
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Sets the purpose of the context. This overrides the default value set by <a href="Store.html#method-i-purpose-3D"><code>Store#purpose=</code></a>.</p>

<p>See also the man page X509_VERIFY_PARAM_set_purpose(3).</p>

          <div class="method-source-code" id="purpose-3D-source">
            <pre>static VALUE
ossl_x509stctx_set_purpose(VALUE self, VALUE purpose)
{
    X509_STORE_CTX *store;
    int p = NUM2INT(purpose);

    GetX509StCtx(self, store);
    X509_STORE_CTX_set_purpose(store, p);

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


      </div>

      <div id="method-i-time-3D" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            time = time
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Sets the time used in the verification. If not set, the current time is used.</p>

<p>See also the man page X509_VERIFY_PARAM_set_time(3).</p>

          <div class="method-source-code" id="time-3D-source">
            <pre>static VALUE
ossl_x509stctx_set_time(VALUE self, VALUE time)
{
    X509_STORE_CTX *store;
    long t;

    t = NUM2LONG(rb_Integer(time));
    GetX509StCtx(self, store);
    X509_STORE_CTX_set_time(store, 0, t);

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


      </div>

      <div id="method-i-trust-3D" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            trust = trust
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Sets the trust settings of the context. This overrides the default value set by <a href="Store.html#method-i-trust-3D"><code>Store#trust=</code></a>.</p>

<p>See also the man page X509_VERIFY_PARAM_set_trust(3).</p>

          <div class="method-source-code" id="trust-3D-source">
            <pre>static VALUE
ossl_x509stctx_set_trust(VALUE self, VALUE trust)
{
    X509_STORE_CTX *store;
    int t = NUM2INT(trust);

    GetX509StCtx(self, store);
    X509_STORE_CTX_set_trust(store, t);

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


      </div>

      <div id="method-i-verify" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            verify &rarr; true | false
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Performs the certificate verification using the parameters set to <em>stctx</em>.</p>

<p>See also the man page X509_verify_cert(3).</p>

          <div class="method-source-code" id="verify-source">
            <pre>static VALUE
ossl_x509stctx_verify(VALUE self)
{
    X509_STORE_CTX *ctx;

    GetX509StCtx(self, ctx);
    X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx,
                               (void *)rb_iv_get(self, &quot;@verify_callback&quot;));

    switch (X509_verify_cert(ctx)) {
      case 1:
        return Qtrue;
      case 0:
        ossl_clear_error();
        return Qfalse;
      default:
        ossl_raise(eX509CertError, &quot;X509_verify_cert&quot;);
    }
}</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>