summaryrefslogtreecommitdiffstats
path: root/OpenSSL/Timestamp/Request.html
blob: 42a8292f08d2e0526763fedd0d892764b9c6c943 (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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
<!DOCTYPE html>

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

<title>class OpenSSL::Timestamp::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-algorithm">#algorithm</a>
    
    <li ><a href="#method-i-algorithm-3D">#algorithm=</a>
    
    <li ><a href="#method-i-cert_requested-3D">#cert_requested=</a>
    
    <li ><a href="#method-i-cert_requested-3F">#cert_requested?</a>
    
    <li ><a href="#method-i-message_imprint">#message_imprint</a>
    
    <li ><a href="#method-i-message_imprint-3D">#message_imprint=</a>
    
    <li ><a href="#method-i-nonce">#nonce</a>
    
    <li ><a href="#method-i-nonce-3D">#nonce=</a>
    
    <li ><a href="#method-i-policy_id">#policy_id</a>
    
    <li ><a href="#method-i-policy_id-3D">#policy_id=</a>
    
    <li ><a href="#method-i-to_der">#to_der</a>
    
    <li ><a href="#method-i-version">#version</a>
    
    <li ><a href="#method-i-version-3D">#version=</a>
    
  </ul>
</div>

  </div>
</nav>

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

  <section class="description">
    
<p>Allows to create timestamp requests or parse existing ones. A <a href="Request.html"><code>Request</code></a> is also needed for creating timestamps from scratch with <a href="Factory.html"><code>Factory</code></a>. When created from scratch, some default values are set:</p>
<ul><li>
<p>version is set to <code>1</code></p>
</li><li>
<p>cert_requested is set to <code>true</code></p>
</li><li>
<p>algorithm, <a href="Request.html#method-i-message_imprint"><code>message_imprint</code></a>, <a href="Request.html#method-i-policy_id"><code>policy_id</code></a>, and nonce are set to <code>false</code></p>
</li></ul>

  </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::Timestamp::Request.new(file)    &rarr; request
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            OpenSSL::Timestamp::Request.new(string)  &rarr; request
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            OpenSSL::Timestamp::Request.new          &rarr; empty request
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>When creating a <a href="Request.html"><code>Request</code></a> with the <code>File</code> or <code>string</code> parameter, the corresponding <code>File</code> or <code>string</code> must be DER-encoded.</p>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_ts_req_initialize(int argc, VALUE *argv, VALUE self)
{
    TS_REQ *ts_req = DATA_PTR(self);
    BIO *in;
    VALUE arg;

    if(rb_scan_args(argc, argv, &quot;01&quot;, &amp;arg) == 0) {
        return self;
    }

    arg = ossl_to_der_if_possible(arg);
    in = ossl_obj2bio(&amp;arg);
    ts_req = d2i_TS_REQ_bio(in, &amp;ts_req);
    BIO_free(in);
    if (!ts_req)
        ossl_raise(eTimestampError, &quot;Error when decoding the timestamp request&quot;);
    DATA_PTR(self) = ts_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-algorithm" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            algorithm    &rarr; string
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the &#39;short name&#39; of the object identifier that represents the algorithm that was used to create the message imprint digest.</p>
          
          

          
          <div class="method-source-code" id="algorithm-source">
            <pre>static VALUE
ossl_ts_req_get_algorithm(VALUE self)
{
    TS_REQ *req;
    TS_MSG_IMPRINT *mi;
    X509_ALGOR *algor;

    GetTSRequest(self, req);
    mi = TS_REQ_get_msg_imprint(req);
    algor = TS_MSG_IMPRINT_get_algo(mi);
    return get_asn1obj(algor-&gt;algorithm);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Allows to set the object identifier  or the &#39;short name&#39; of the algorithm that was used to create the message imprint digest.</p>

<h3 id="method-i-algorithm-3D-label-Example-3A">Example:<span><a href="#method-i-algorithm-3D-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">request</span>.<span class="ruby-identifier">algorithm</span> = <span class="ruby-string">&quot;SHA1&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="algorithm-3D-source">
            <pre>static VALUE
ossl_ts_req_set_algorithm(VALUE self, VALUE algo)
{
    TS_REQ *req;
    TS_MSG_IMPRINT *mi;
    ASN1_OBJECT *obj;
    X509_ALGOR *algor;

    GetTSRequest(self, req);
    obj = obj_to_asn1obj(algo);
    mi = TS_REQ_get_msg_imprint(req);
    algor = TS_MSG_IMPRINT_get_algo(mi);
    if (!X509_ALGOR_set0(algor, obj, V_ASN1_NULL, NULL)) {
        ASN1_OBJECT_free(obj);
        ossl_raise(eTimestampError, &quot;X509_ALGOR_set0&quot;);
    }

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Specify whether the response shall contain the timestamp authority&#39;s certificate or not. The default value is <code>true</code>.</p>
          
          

          
          <div class="method-source-code" id="cert_requested-3D-source">
            <pre>static VALUE
ossl_ts_req_set_cert_requested(VALUE self, VALUE requested)
{
    TS_REQ *req;

    GetTSRequest(self, req);
    TS_REQ_set_cert_req(req, RTEST(requested));

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Indicates whether the response shall contain the timestamp authority&#39;s certificate or not.</p>
          
          

          
          <div class="method-source-code" id="cert_requested-3F-source">
            <pre>static VALUE
ossl_ts_req_get_cert_requested(VALUE self)
{
    TS_REQ *req;

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the message imprint (digest) of the data to be timestamped.</p>
          
          

          
          <div class="method-source-code" id="message_imprint-source">
            <pre>static VALUE
ossl_ts_req_get_msg_imprint(VALUE self)
{
    TS_REQ *req;
    TS_MSG_IMPRINT *mi;
    ASN1_OCTET_STRING *hashed_msg;
    VALUE ret;

    GetTSRequest(self, req);
    mi = TS_REQ_get_msg_imprint(req);
    hashed_msg = TS_MSG_IMPRINT_get_msg(mi);

    ret = rb_str_new((const char *)hashed_msg-&gt;data, hashed_msg-&gt;length);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Set the message imprint digest.</p>
          
          

          
          <div class="method-source-code" id="message_imprint-3D-source">
            <pre>static VALUE
ossl_ts_req_set_msg_imprint(VALUE self, VALUE hash)
{
    TS_REQ *req;
    TS_MSG_IMPRINT *mi;
    StringValue(hash);

    GetTSRequest(self, req);
    mi = TS_REQ_get_msg_imprint(req);
    if (!TS_MSG_IMPRINT_set_msg(mi, (unsigned char *)RSTRING_PTR(hash), RSTRING_LENINT(hash)))
        ossl_raise(eTimestampError, &quot;TS_MSG_IMPRINT_set_msg&quot;);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the nonce (number used once) that the server shall include in its response.</p>
          
          

          
          <div class="method-source-code" id="nonce-source">
            <pre>static VALUE
ossl_ts_req_get_nonce(VALUE self)
{
    TS_REQ *req;
    const ASN1_INTEGER * nonce;

    GetTSRequest(self, req);
    if (!(nonce = TS_REQ_get_nonce(req)))
        return Qnil;
    return asn1integer_to_num(nonce);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-nonce-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            nonce = number    &rarr; BN
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the nonce (number used once) that the server shall include in its response. If the nonce is set, the server must return the same nonce value in a valid <a href="Response.html"><code>Response</code></a>.</p>
          
          

          
          <div class="method-source-code" id="nonce-3D-source">
            <pre>static VALUE
ossl_ts_req_set_nonce(VALUE self, VALUE num)
{
    TS_REQ *req;
    ASN1_INTEGER *nonce;
    int ok;

    GetTSRequest(self, req);
    nonce = num_to_asn1integer(num, NULL);
    ok = TS_REQ_set_nonce(req, nonce);
    ASN1_INTEGER_free(nonce);
    if (!ok)
        ossl_raise(eTimestampError, NULL);
    return num;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the &#39;short name&#39; of the object identifier that represents the timestamp policy under which the server shall create the timestamp.</p>
          
          

          
          <div class="method-source-code" id="policy_id-source">
            <pre>static VALUE
ossl_ts_req_get_policy_id(VALUE self)
{
    TS_REQ *req;

    GetTSRequest(self, req);
    if (!TS_REQ_get_policy_id(req))
        return Qnil;
    return get_asn1obj(TS_REQ_get_policy_id(req));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Allows to set the object identifier that represents the timestamp policy under which the server shall create the timestamp. This may be left <code>nil</code>, implying that the timestamp server will issue the timestamp using some default policy.</p>

<h3 id="method-i-policy_id-3D-label-Example-3A">Example:<span><a href="#method-i-policy_id-3D-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">request</span>.<span class="ruby-identifier">policy_id</span> = <span class="ruby-string">&quot;1.2.3.4.5&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="policy_id-3D-source">
            <pre>static VALUE
ossl_ts_req_set_policy_id(VALUE self, VALUE oid)
{
    TS_REQ *req;
    ASN1_OBJECT *obj;
    int ok;

    GetTSRequest(self, req);
    obj = obj_to_asn1obj(oid);
    ok = TS_REQ_set_policy_id(req, obj);
    ASN1_OBJECT_free(obj);
    if (!ok)
        ossl_raise(eTimestampError, &quot;TS_REQ_set_policy_id&quot;);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>DER-encodes this <a href="Request.html"><code>Request</code></a>.</p>
          
          

          
          <div class="method-source-code" id="to_der-source">
            <pre>static VALUE
ossl_ts_req_to_der(VALUE self)
{
    TS_REQ *req;
    TS_MSG_IMPRINT *mi;
    X509_ALGOR *algo;
    ASN1_OCTET_STRING *hashed_msg;

    GetTSRequest(self, req);
    mi = TS_REQ_get_msg_imprint(req);

    algo = TS_MSG_IMPRINT_get_algo(mi);
    if (OBJ_obj2nid(algo-&gt;algorithm) == NID_undef)
        ossl_raise(eTimestampError, &quot;Message imprint missing algorithm&quot;);

    hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
    if (!hashed_msg-&gt;length)
        ossl_raise(eTimestampError, &quot;Message imprint missing hashed message&quot;);

    return asn1_to_der((void *)req, (int (*)(void *, unsigned char **))i2d_TS_REQ);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the version of this request. <code>1</code> is the default value.</p>
          
          

          
          <div class="method-source-code" id="version-source">
            <pre>static VALUE
ossl_ts_req_get_version(VALUE self)
{
    TS_REQ *req;

    GetTSRequest(self, req);
    return LONG2NUM(TS_REQ_get_version(req));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Sets the version number for this <a href="Request.html"><code>Request</code></a>. This should be <code>1</code> for compliant servers.</p>
          
          

          
          <div class="method-source-code" id="version-3D-source">
            <pre>static VALUE
ossl_ts_req_set_version(VALUE self, VALUE version)
{
    TS_REQ *req;
    long ver;

    if ((ver = NUM2LONG(version)) &lt; 0)
        ossl_raise(eTimestampError, &quot;version must be &gt;= 0!&quot;);
    GetTSRequest(self, req);
    if (!TS_REQ_set_version(req, ver))
        ossl_raise(eTimestampError, &quot;TS_REQ_set_version&quot;);

    return version;
}</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.2.1.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>