summaryrefslogtreecommitdiffstats
path: root/OpenSSL/OCSP/Request.html
blob: 0374f7c76fa7d2b35fbfcaeb91f06c579be1ecff (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
<!DOCTYPE html>

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

<title>class OpenSSL::OCSP::Request - 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-add_certid">#add_certid</a>
    <li ><a href="#method-i-add_nonce">#add_nonce</a>
    <li ><a href="#method-i-certid">#certid</a>
    <li ><a href="#method-i-check_nonce">#check_nonce</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-sign">#sign</a>
    <li ><a href="#method-i-signed-3F">#signed?</a>
    <li ><a href="#method-i-to_der">#to_der</a>
    <li ><a href="#method-i-verify">#verify</a>
  </ul>
</div>

  </div>
</nav>

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

  <section class="description">
    
<p>An <a href="Request.html"><code>OpenSSL::OCSP::Request</code></a> contains the certificate information for determining if a certificate has been revoked or not.  A <a href="Request.html"><code>Request</code></a> can be created for a certificate or from a DER-encoded request created elsewhere.</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">
            OpenSSL::OCSP::Request.new              &rarr; request
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        <div class="method-heading">
          <span class="method-callseq">
            OpenSSL::OCSP::Request.new(request_der) &rarr; request
          </span>
        </div>

        <div class="method-description">
          <p>Creates a new <a href="Request.html"><code>OpenSSL::OCSP::Request</code></a>.  The request may be created empty or from a <em>request_der</em> string.</p>

          <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_ocspreq_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE arg;
    OCSP_REQUEST *req, *req_new;
    const unsigned char *p;

    rb_scan_args(argc, argv, &quot;01&quot;, &amp;arg);
    if(!NIL_P(arg)){
        GetOCSPReq(self, req);
        arg = ossl_to_der_if_possible(arg);
        StringValue(arg);
        p = (unsigned char *)RSTRING_PTR(arg);
        req_new = d2i_OCSP_REQUEST(NULL, &amp;p, RSTRING_LEN(arg));
        if (!req_new)
            ossl_raise(eOCSPError, &quot;d2i_OCSP_REQUEST&quot;);
        SetOCSPReq(self, req_new);
        OCSP_REQUEST_free(req);
    }

    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-add_certid" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            add_certid(certificate_id) &rarr; request
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Adds <em>certificate_id</em> to the request.</p>

          <div class="method-source-code" id="add_certid-source">
            <pre>static VALUE
ossl_ocspreq_add_certid(VALUE self, VALUE certid)
{
    OCSP_REQUEST *req;
    OCSP_CERTID *id, *id_new;

    GetOCSPReq(self, req);
    GetOCSPCertId(certid, id);

    if (!(id_new = OCSP_CERTID_dup(id)))
        ossl_raise(eOCSPError, &quot;OCSP_CERTID_dup&quot;);
    if (!OCSP_request_add0_id(req, id_new)) {
        OCSP_CERTID_free(id_new);
        ossl_raise(eOCSPError, &quot;OCSP_request_add0_id&quot;);
    }

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


      </div>

      <div id="method-i-add_nonce" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            add_nonce(nonce = nil) &rarr; request
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Adds a <em>nonce</em> to the <a href="../OCSP.html"><code>OCSP</code></a> request.  If no nonce is given a random one will be generated.</p>

<p>The nonce is used to prevent replay attacks but some servers do not support it.</p>

          <div class="method-source-code" id="add_nonce-source">
            <pre>static VALUE
ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
{
    OCSP_REQUEST *req;
    VALUE val;
    int ret;

    rb_scan_args(argc, argv, &quot;01&quot;, &amp;val);
    if(NIL_P(val)) {
        GetOCSPReq(self, req);
        ret = OCSP_request_add1_nonce(req, NULL, -1);
    }
    else{
        StringValue(val);
        GetOCSPReq(self, req);
        ret = OCSP_request_add1_nonce(req, (unsigned char *)RSTRING_PTR(val), RSTRING_LENINT(val));
    }
    if(!ret) ossl_raise(eOCSPError, NULL);

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


      </div>

      <div id="method-i-certid" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            certid &rarr; [certificate_id, ...]
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns all certificate IDs in this request.</p>

          <div class="method-source-code" id="certid-source">
            <pre>static VALUE
ossl_ocspreq_get_certid(VALUE self)
{
    OCSP_REQUEST *req;
    OCSP_ONEREQ *one;
    OCSP_CERTID *id;
    VALUE ary, tmp;
    int i, count;

    GetOCSPReq(self, req);
    count = OCSP_request_onereq_count(req);
    ary = (count &gt; 0) ? rb_ary_new() : Qnil;
    for(i = 0; i &lt; count; i++){
        one = OCSP_request_onereq_get0(req, i);
        tmp = NewOCSPCertId(cOCSPCertId);
        if(!(id = OCSP_CERTID_dup(OCSP_onereq_get0_id(one))))
            ossl_raise(eOCSPError, NULL);
        SetOCSPCertId(tmp, id);
        rb_ary_push(ary, tmp);
    }

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


      </div>

      <div id="method-i-check_nonce" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            check_nonce(response) &rarr; result
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Checks the nonce validity for this request and <em>response</em>.</p>

<p>The return value is one of the following:</p>
<dl class="rdoc-list note-list"><dt>-1 
<dd>
<p>nonce in request only.</p>
</dd><dt>0 
<dd>
<p>nonces both present and not equal.</p>
</dd><dt>1 
<dd>
<p>nonces present and equal.</p>
</dd><dt>2 
<dd>
<p>nonces both absent.</p>
</dd><dt>3 
<dd>
<p>nonce present in response only.</p>
</dd></dl>

<p>For most responses, clients can check <em>result</em> &gt; 0.  If a responder doesn’t handle nonces <code>result.nonzero?</code> may be necessary.  A result of <code>0</code> is always an error.</p>

          <div class="method-source-code" id="check_nonce-source">
            <pre>static VALUE
ossl_ocspreq_check_nonce(VALUE self, VALUE basic_resp)
{
    OCSP_REQUEST *req;
    OCSP_BASICRESP *bs;
    int res;

    GetOCSPReq(self, req);
    GetOCSPBasicRes(basic_resp, bs);
    res = OCSP_check_nonce(req, bs);

    return INT2NUM(res);
}</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
ossl_ocspreq_initialize_copy(VALUE self, VALUE other)
{
    OCSP_REQUEST *req, *req_old, *req_new;

    rb_check_frozen(self);
    GetOCSPReq(self, req_old);
    GetOCSPReq(other, req);

    req_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_REQUEST), req);
    if (!req_new)
        ossl_raise(eOCSPError, &quot;ASN1_item_dup&quot;);

    SetOCSPReq(self, req_new);
    OCSP_REQUEST_free(req_old);

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


      </div>

      <div id="method-i-sign" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            sign(cert, key, certs = nil, flags = 0, digest = nil) &rarr; self
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Signs this <a href="../OCSP.html"><code>OCSP</code></a> request using <em>cert</em>, <em>key</em> and optional <em>digest</em>. If <em>digest</em> is not specified, SHA-1 is used. <em>certs</em> is an optional Array of additional certificates which are included in the request in addition to the signer certificate. Note that if <em>certs</em> is <code>nil</code> or not given, flag OpenSSL::OCSP::NOCERTS is enabled. Pass an empty array to include only the signer certificate.</p>

<p><em>flags</em> is a bitwise OR of the following constants:</p>
<dl class="rdoc-list note-list"><dt>OpenSSL::OCSP::NOCERTS
<dd>
<p>Don’t include any certificates in the request. <em>certs</em> will be ignored.</p>
</dd></dl>

          <div class="method-source-code" id="sign-source">
            <pre>static VALUE
ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
{
    VALUE signer_cert, signer_key, certs, flags, digest;
    OCSP_REQUEST *req;
    X509 *signer;
    EVP_PKEY *key;
    STACK_OF(X509) *x509s = NULL;
    unsigned long flg = 0;
    const EVP_MD *md;
    int ret;

    rb_scan_args(argc, argv, &quot;23&quot;, &amp;signer_cert, &amp;signer_key, &amp;certs, &amp;flags, &amp;digest);
    GetOCSPReq(self, req);
    signer = GetX509CertPtr(signer_cert);
    key = GetPrivPKeyPtr(signer_key);
    if (!NIL_P(flags))
        flg = NUM2INT(flags);
    if (NIL_P(digest))
        md = EVP_sha1();
    else
        md = ossl_evp_get_digestbyname(digest);
    if (NIL_P(certs))
        flg |= OCSP_NOCERTS;
    else
        x509s = ossl_x509_ary2sk(certs);

    ret = OCSP_request_sign(req, signer, key, md, x509s, flg);
    sk_X509_pop_free(x509s, X509_free);
    if (!ret) ossl_raise(eOCSPError, NULL);

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


      </div>

      <div id="method-i-signed-3F" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            signed? &rarr; true or false
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns <code>true</code> if the request is signed, <code>false</code> otherwise. Note that the validity of the signature is <strong>not</strong> checked. Use <a href="Request.html#method-i-verify"><code>verify</code></a> to verify that.</p>

          <div class="method-source-code" id="signed-3F-source">
            <pre>static VALUE
ossl_ocspreq_signed_p(VALUE self)
{
    OCSP_REQUEST *req;

    GetOCSPReq(self, req);
    return OCSP_request_is_signed(req) ? Qtrue : Qfalse;
}</pre>
          </div>
        </div>


      </div>

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

        <div class="method-description">
          <p>Returns this request as a DER-encoded string</p>

          <div class="method-source-code" id="to_der-source">
            <pre>static VALUE
ossl_ocspreq_to_der(VALUE self)
{
    OCSP_REQUEST *req;
    VALUE str;
    unsigned char *p;
    long len;

    GetOCSPReq(self, req);
    if((len = i2d_OCSP_REQUEST(req, NULL)) &lt;= 0)
        ossl_raise(eOCSPError, NULL);
    str = rb_str_new(0, len);
    p = (unsigned char *)RSTRING_PTR(str);
    if(i2d_OCSP_REQUEST(req, &amp;p) &lt;= 0)
        ossl_raise(eOCSPError, NULL);
    ossl_str_adjust(str, p);

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


      </div>

      <div id="method-i-verify" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            verify(certificates, store, flags = 0) &rarr; true or false
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Verifies this request using the given <em>certificates</em> and <em>store</em>. <em>certificates</em> is an array of <a href="../X509/Certificate.html"><code>OpenSSL::X509::Certificate</code></a>, <em>store</em> is an <a href="../X509/Store.html"><code>OpenSSL::X509::Store</code></a>.</p>

<p>Note that <code>false</code> is returned if the request does not have a signature. Use <a href="Request.html#method-i-signed-3F"><code>signed?</code></a> to check whether the request is signed or not.</p>

          <div class="method-source-code" id="verify-source">
            <pre>static VALUE
ossl_ocspreq_verify(int argc, VALUE *argv, VALUE self)
{
    VALUE certs, store, flags;
    OCSP_REQUEST *req;
    STACK_OF(X509) *x509s;
    X509_STORE *x509st;
    int flg, result;

    rb_scan_args(argc, argv, &quot;21&quot;, &amp;certs, &amp;store, &amp;flags);
    GetOCSPReq(self, req);
    x509st = GetX509StorePtr(store);
    flg = NIL_P(flags) ? 0 : NUM2INT(flags);
    x509s = ossl_x509_ary2sk(certs);
    result = OCSP_request_verify(req, x509s, x509st, flg);
    sk_X509_pop_free(x509s, X509_free);
    if (result &lt;= 0)
        ossl_clear_error();

    return result &gt; 0 ? Qtrue : Qfalse;
}</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>