openssl 3.2.4 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +180 -29
  3. data/History.md +69 -42
  4. data/README.md +11 -7
  5. data/ext/openssl/extconf.rb +6 -5
  6. data/ext/openssl/openssl_missing.c +1 -2
  7. data/ext/openssl/openssl_missing.h +1 -28
  8. data/ext/openssl/ossl.c +8 -10
  9. data/ext/openssl/ossl.h +13 -10
  10. data/ext/openssl/ossl_asn1.c +77 -273
  11. data/ext/openssl/ossl_asn1.h +1 -19
  12. data/ext/openssl/ossl_bio.c +1 -1
  13. data/ext/openssl/ossl_bio.h +1 -1
  14. data/ext/openssl/ossl_bn.c +12 -12
  15. data/ext/openssl/ossl_bn.h +1 -2
  16. data/ext/openssl/ossl_cipher.c +5 -5
  17. data/ext/openssl/ossl_cipher.h +1 -4
  18. data/ext/openssl/ossl_config.c +10 -9
  19. data/ext/openssl/ossl_config.h +1 -1
  20. data/ext/openssl/ossl_digest.c +39 -21
  21. data/ext/openssl/ossl_digest.h +1 -4
  22. data/ext/openssl/ossl_engine.c +3 -3
  23. data/ext/openssl/ossl_engine.h +1 -4
  24. data/ext/openssl/ossl_hmac.c +3 -3
  25. data/ext/openssl/ossl_hmac.h +1 -4
  26. data/ext/openssl/ossl_kdf.c +5 -5
  27. data/ext/openssl/ossl_ns_spki.c +13 -12
  28. data/ext/openssl/ossl_ns_spki.h +1 -5
  29. data/ext/openssl/ossl_ocsp.c +16 -16
  30. data/ext/openssl/ossl_ocsp.h +1 -8
  31. data/ext/openssl/ossl_pkcs12.c +54 -3
  32. data/ext/openssl/ossl_pkcs12.h +1 -4
  33. data/ext/openssl/ossl_pkcs7.c +69 -22
  34. data/ext/openssl/ossl_pkcs7.h +2 -22
  35. data/ext/openssl/ossl_pkey.c +22 -63
  36. data/ext/openssl/ossl_pkey.h +3 -14
  37. data/ext/openssl/ossl_pkey_dh.c +2 -4
  38. data/ext/openssl/ossl_pkey_dsa.c +2 -4
  39. data/ext/openssl/ossl_pkey_ec.c +6 -8
  40. data/ext/openssl/ossl_pkey_rsa.c +2 -4
  41. data/ext/openssl/ossl_provider.c +3 -1
  42. data/ext/openssl/ossl_rand.c +3 -3
  43. data/ext/openssl/ossl_rand.h +1 -4
  44. data/ext/openssl/ossl_ssl.c +71 -52
  45. data/ext/openssl/ossl_ssl.h +1 -1
  46. data/ext/openssl/ossl_ts.c +77 -19
  47. data/ext/openssl/ossl_ts.h +1 -1
  48. data/ext/openssl/ossl_x509.c +1 -1
  49. data/ext/openssl/ossl_x509.h +7 -26
  50. data/ext/openssl/ossl_x509attr.c +30 -32
  51. data/ext/openssl/ossl_x509cert.c +48 -9
  52. data/ext/openssl/ossl_x509crl.c +13 -9
  53. data/ext/openssl/ossl_x509ext.c +12 -21
  54. data/ext/openssl/ossl_x509name.c +8 -10
  55. data/ext/openssl/ossl_x509req.c +10 -6
  56. data/ext/openssl/ossl_x509revoked.c +5 -6
  57. data/ext/openssl/ossl_x509store.c +21 -14
  58. data/lib/openssl/asn1.rb +188 -0
  59. data/lib/openssl/bn.rb +1 -1
  60. data/lib/openssl/buffering.rb +13 -3
  61. data/lib/openssl/cipher.rb +1 -1
  62. data/lib/openssl/digest.rb +1 -1
  63. data/lib/openssl/marshal.rb +1 -1
  64. data/lib/openssl/ssl.rb +68 -4
  65. data/lib/openssl/version.rb +1 -1
  66. data/lib/openssl/x509.rb +1 -1
  67. data/lib/openssl.rb +2 -1
  68. metadata +9 -4
  69. /data/{LICENSE.txt → COPYING} +0 -0
data/ext/openssl/ossl.h CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_H_)
11
11
  #define _OSSL_H_
@@ -17,6 +17,12 @@
17
17
  #include <errno.h>
18
18
  #include <ruby/io.h>
19
19
  #include <ruby/thread.h>
20
+ #ifdef HAVE_RUBY_RACTOR_H
21
+ #include <ruby/ractor.h>
22
+ #else
23
+ #define RUBY_TYPED_FROZEN_SHAREABLE 0
24
+ #endif
25
+
20
26
  #include <openssl/opensslv.h>
21
27
 
22
28
  #include <openssl/err.h>
@@ -39,6 +45,7 @@
39
45
  #include <openssl/dsa.h>
40
46
  #include <openssl/evp.h>
41
47
  #include <openssl/dh.h>
48
+ #include "openssl_missing.h"
42
49
 
43
50
  #ifndef LIBRESSL_VERSION_NUMBER
44
51
  # define OSSL_IS_LIBRESSL 0
@@ -64,7 +71,6 @@
64
71
 
65
72
  #if OSSL_OPENSSL_PREREQ(3, 0, 0)
66
73
  # define OSSL_USE_PROVIDER
67
- # include <openssl/provider.h>
68
74
  #endif
69
75
 
70
76
  /*
@@ -120,7 +126,7 @@ do{\
120
126
  * Convert binary string to hex string. The caller is responsible for
121
127
  * ensuring out has (2 * len) bytes of capacity.
122
128
  */
123
- void ossl_bin2hex(const unsigned char *in, char *out, size_t len);
129
+ void ossl_bin2hex(unsigned char *in, char *out, size_t len);
124
130
 
125
131
  /*
126
132
  * Our default PEM callback
@@ -173,28 +179,25 @@ extern VALUE dOSSL;
173
179
  /*
174
180
  * Include all parts
175
181
  */
176
- #include "openssl_missing.h"
177
182
  #include "ossl_asn1.h"
178
183
  #include "ossl_bio.h"
179
184
  #include "ossl_bn.h"
180
185
  #include "ossl_cipher.h"
181
186
  #include "ossl_config.h"
182
187
  #include "ossl_digest.h"
188
+ #include "ossl_engine.h"
183
189
  #include "ossl_hmac.h"
190
+ #include "ossl_kdf.h"
184
191
  #include "ossl_ns_spki.h"
185
192
  #include "ossl_ocsp.h"
186
193
  #include "ossl_pkcs12.h"
187
194
  #include "ossl_pkcs7.h"
188
195
  #include "ossl_pkey.h"
196
+ #include "ossl_provider.h"
189
197
  #include "ossl_rand.h"
190
198
  #include "ossl_ssl.h"
191
- #ifndef OPENSSL_NO_TS
192
- #include "ossl_ts.h"
193
- #endif
199
+ #include "ossl_ts.h"
194
200
  #include "ossl_x509.h"
195
- #include "ossl_engine.h"
196
- #include "ossl_provider.h"
197
- #include "ossl_kdf.h"
198
201
 
199
202
  void Init_openssl(void);
200
203
 
@@ -5,30 +5,28 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
12
12
  static VALUE ossl_asn1_decode0(unsigned char **pp, long length, long *offset,
13
13
  int depth, int yield, long *num_read);
14
- static VALUE ossl_asn1_initialize(int argc, VALUE *argv, VALUE self);
15
14
 
16
15
  /*
17
16
  * DATE conversion
18
17
  */
19
18
  VALUE
20
- asn1time_to_time(const ASN1_TIME *time_)
19
+ asn1time_to_time(const ASN1_TIME *time)
21
20
  {
22
- ASN1_TIME *time = (ASN1_TIME *)time_; // const cast for OpenSSL 1.0.2
23
21
  struct tm tm;
24
22
  VALUE argv[6];
25
23
  int count;
26
24
 
27
25
  memset(&tm, 0, sizeof(struct tm));
28
26
 
29
- switch (ASN1_STRING_type(time)) {
27
+ switch (time->type) {
30
28
  case V_ASN1_UTCTIME:
31
- count = sscanf((const char *)ASN1_STRING_get0_data(time), "%2d%2d%2d%2d%2d%2dZ",
29
+ count = sscanf((const char *)time->data, "%2d%2d%2d%2d%2d%2dZ",
32
30
  &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min,
33
31
  &tm.tm_sec);
34
32
 
@@ -36,7 +34,7 @@ asn1time_to_time(const ASN1_TIME *time_)
36
34
  tm.tm_sec = 0;
37
35
  } else if (count != 6) {
38
36
  ossl_raise(rb_eTypeError, "bad UTCTIME format: \"%s\"",
39
- ASN1_STRING_get0_data(time));
37
+ time->data);
40
38
  }
41
39
  if (tm.tm_year < 69) {
42
40
  tm.tm_year += 2000;
@@ -45,7 +43,7 @@ asn1time_to_time(const ASN1_TIME *time_)
45
43
  }
46
44
  break;
47
45
  case V_ASN1_GENERALIZEDTIME:
48
- count = sscanf((const char *)ASN1_STRING_get0_data(time), "%4d%2d%2d%2d%2d%2dZ",
46
+ count = sscanf((const char *)time->data, "%4d%2d%2d%2d%2d%2dZ",
49
47
  &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min,
50
48
  &tm.tm_sec);
51
49
  if (count == 5) {
@@ -53,7 +51,7 @@ asn1time_to_time(const ASN1_TIME *time_)
53
51
  }
54
52
  else if (count != 6) {
55
53
  ossl_raise(rb_eTypeError, "bad GENERALIZEDTIME format: \"%s\"",
56
- ASN1_STRING_get0_data(time));
54
+ time->data);
57
55
  }
58
56
  break;
59
57
  default:
@@ -98,8 +96,7 @@ ossl_time_split(VALUE time, time_t *sec, int *days)
98
96
  VALUE
99
97
  asn1str_to_str(const ASN1_STRING *str)
100
98
  {
101
- return rb_str_new((const char *)ASN1_STRING_get0_data(str),
102
- ASN1_STRING_length(str));
99
+ return rb_str_new((const char *)str->data, str->length);
103
100
  }
104
101
 
105
102
  /*
@@ -114,9 +111,9 @@ asn1integer_to_num(const ASN1_INTEGER *ai)
114
111
  if (!ai) {
115
112
  ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
116
113
  }
117
- if (ASN1_STRING_type((ASN1_STRING *)ai) == V_ASN1_ENUMERATED)
118
- /* const_cast: workaround for old OpenSSL */
119
- bn = ASN1_ENUMERATED_to_BN((ASN1_ENUMERATED *)ai, NULL);
114
+ if (ai->type == V_ASN1_ENUMERATED)
115
+ /* const_cast: workaround for old OpenSSL */
116
+ bn = ASN1_ENUMERATED_to_BN((ASN1_ENUMERATED *)ai, NULL);
120
117
  else
121
118
  bn = ASN1_INTEGER_to_BN(ai, NULL);
122
119
 
@@ -160,38 +157,33 @@ asn1integer_to_num_i(VALUE arg)
160
157
  #define ossl_asn1_get_tag_class(o) rb_attr_get((o),sivTAG_CLASS)
161
158
  #define ossl_asn1_get_indefinite_length(o) rb_attr_get((o),sivINDEFINITE_LENGTH)
162
159
 
163
- #define ossl_asn1_set_value(o,v) rb_ivar_set((o),sivVALUE,(v))
164
- #define ossl_asn1_set_tag(o,v) rb_ivar_set((o),sivTAG,(v))
165
- #define ossl_asn1_set_tagging(o,v) rb_ivar_set((o),sivTAGGING,(v))
166
- #define ossl_asn1_set_tag_class(o,v) rb_ivar_set((o),sivTAG_CLASS,(v))
167
160
  #define ossl_asn1_set_indefinite_length(o,v) rb_ivar_set((o),sivINDEFINITE_LENGTH,(v))
168
161
 
169
162
  VALUE mASN1;
170
163
  VALUE eASN1Error;
171
164
 
172
165
  VALUE cASN1Data;
173
- VALUE cASN1Primitive;
174
- VALUE cASN1Constructive;
175
-
176
- VALUE cASN1EndOfContent;
177
- VALUE cASN1Boolean; /* BOOLEAN */
178
- VALUE cASN1Integer, cASN1Enumerated; /* INTEGER */
179
- VALUE cASN1BitString; /* BIT STRING */
180
- VALUE cASN1OctetString, cASN1UTF8String; /* STRINGs */
181
- VALUE cASN1NumericString, cASN1PrintableString;
182
- VALUE cASN1T61String, cASN1VideotexString;
183
- VALUE cASN1IA5String, cASN1GraphicString;
184
- VALUE cASN1ISO64String, cASN1GeneralString;
185
- VALUE cASN1UniversalString, cASN1BMPString;
186
- VALUE cASN1Null; /* NULL */
187
- VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
188
- VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
189
- VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */
166
+ static VALUE cASN1Primitive;
167
+ static VALUE cASN1Constructive;
168
+
169
+ static VALUE cASN1EndOfContent;
170
+ static VALUE cASN1Boolean; /* BOOLEAN */
171
+ static VALUE cASN1Integer, cASN1Enumerated; /* INTEGER */
172
+ static VALUE cASN1BitString; /* BIT STRING */
173
+ static VALUE cASN1OctetString, cASN1UTF8String; /* STRINGs */
174
+ static VALUE cASN1NumericString, cASN1PrintableString;
175
+ static VALUE cASN1T61String, cASN1VideotexString;
176
+ static VALUE cASN1IA5String, cASN1GraphicString;
177
+ static VALUE cASN1ISO64String, cASN1GeneralString;
178
+ static VALUE cASN1UniversalString, cASN1BMPString;
179
+ static VALUE cASN1Null; /* NULL */
180
+ static VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
181
+ static VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
182
+ static VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */
190
183
 
191
184
  static VALUE sym_IMPLICIT, sym_EXPLICIT;
192
185
  static VALUE sym_UNIVERSAL, sym_APPLICATION, sym_CONTEXT_SPECIFIC, sym_PRIVATE;
193
186
  static ID sivVALUE, sivTAG, sivTAG_CLASS, sivTAGGING, sivINDEFINITE_LENGTH, sivUNUSED_BITS;
194
- static ID id_each;
195
187
 
196
188
  /*
197
189
  * Ruby to ASN1 converters
@@ -212,7 +204,7 @@ obj_to_asn1int(VALUE obj)
212
204
  }
213
205
 
214
206
  static ASN1_BIT_STRING*
215
- obj_to_asn1bstr(VALUE obj, int unused_bits)
207
+ obj_to_asn1bstr(VALUE obj, long unused_bits)
216
208
  {
217
209
  ASN1_BIT_STRING *bstr;
218
210
 
@@ -220,11 +212,11 @@ obj_to_asn1bstr(VALUE obj, int unused_bits)
220
212
  ossl_raise(eASN1Error, "unused_bits for a bitstring value must be in "\
221
213
  "the range 0 to 7");
222
214
  StringValue(obj);
223
- if (!(bstr = ASN1_BIT_STRING_new()))
224
- ossl_raise(eASN1Error, "ASN1_BIT_STRING_new");
225
- if (!ASN1_BIT_STRING_set1(bstr, (uint8_t *)RSTRING_PTR(obj),
226
- RSTRING_LEN(obj), unused_bits))
227
- ossl_raise(eASN1Error, "ASN1_BIT_STRING_set1");
215
+ if(!(bstr = ASN1_BIT_STRING_new()))
216
+ ossl_raise(eASN1Error, NULL);
217
+ ASN1_BIT_STRING_set(bstr, (unsigned char *)RSTRING_PTR(obj), RSTRING_LENINT(obj));
218
+ bstr->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
219
+ bstr->flags |= ASN1_STRING_FLAG_BITS_LEFT | unused_bits;
228
220
 
229
221
  return bstr;
230
222
  }
@@ -348,25 +340,22 @@ decode_int(unsigned char* der, long length)
348
340
  }
349
341
 
350
342
  static VALUE
351
- decode_bstr(unsigned char* der, long length, int *unused_bits)
343
+ decode_bstr(unsigned char* der, long length, long *unused_bits)
352
344
  {
353
345
  ASN1_BIT_STRING *bstr;
354
346
  const unsigned char *p;
355
- size_t len;
347
+ long len;
356
348
  VALUE ret;
357
- int state;
358
349
 
359
350
  p = der;
360
- if (!(bstr = d2i_ASN1_BIT_STRING(NULL, &p, length)))
361
- ossl_raise(eASN1Error, "d2i_ASN1_BIT_STRING");
362
- if (!ASN1_BIT_STRING_get_length(bstr, &len, unused_bits)) {
363
- ASN1_BIT_STRING_free(bstr);
364
- ossl_raise(eASN1Error, "ASN1_BIT_STRING_get_length");
365
- }
366
- ret = ossl_str_new((const char *)ASN1_STRING_get0_data(bstr), len, &state);
351
+ if(!(bstr = d2i_ASN1_BIT_STRING(NULL, &p, length)))
352
+ ossl_raise(eASN1Error, NULL);
353
+ len = bstr->length;
354
+ *unused_bits = 0;
355
+ if(bstr->flags & ASN1_STRING_FLAG_BITS_LEFT)
356
+ *unused_bits = bstr->flags & 0x07;
357
+ ret = rb_str_new((const char *)bstr->data, len);
367
358
  ASN1_BIT_STRING_free(bstr);
368
- if (state)
369
- rb_jump_tag(state);
370
359
 
371
360
  return ret;
372
361
  }
@@ -508,7 +497,7 @@ static VALUE class_tag_map;
508
497
 
509
498
  static int ossl_asn1_default_tag(VALUE obj);
510
499
 
511
- ASN1_TYPE*
500
+ static ASN1_TYPE *
512
501
  ossl_asn1_get_asn1type(VALUE obj)
513
502
  {
514
503
  ASN1_TYPE *ret;
@@ -643,35 +632,6 @@ ossl_asn1_class2sym(int tc)
643
632
  return sym_UNIVERSAL;
644
633
  }
645
634
 
646
- /*
647
- * call-seq:
648
- * OpenSSL::ASN1::ASN1Data.new(value, tag, tag_class) => ASN1Data
649
- *
650
- * _value_: Please have a look at Constructive and Primitive to see how Ruby
651
- * types are mapped to ASN.1 types and vice versa.
652
- *
653
- * _tag_: An Integer indicating the tag number.
654
- *
655
- * _tag_class_: A Symbol indicating the tag class. Please cf. ASN1 for
656
- * possible values.
657
- *
658
- * == Example
659
- * asn1_int = OpenSSL::ASN1Data.new(42, 2, :UNIVERSAL) # => Same as OpenSSL::ASN1::Integer.new(42)
660
- * tagged_int = OpenSSL::ASN1Data.new(42, 0, :CONTEXT_SPECIFIC) # implicitly 0-tagged INTEGER
661
- */
662
- static VALUE
663
- ossl_asn1data_initialize(VALUE self, VALUE value, VALUE tag, VALUE tag_class)
664
- {
665
- if(!SYMBOL_P(tag_class))
666
- ossl_raise(eASN1Error, "invalid tag class");
667
- ossl_asn1_set_tag(self, tag);
668
- ossl_asn1_set_value(self, value);
669
- ossl_asn1_set_tag_class(self, tag_class);
670
- ossl_asn1_set_indefinite_length(self, Qfalse);
671
-
672
- return self;
673
- }
674
-
675
635
  static VALUE
676
636
  to_der_internal(VALUE self, int constructed, int indef_len, VALUE body)
677
637
  {
@@ -751,7 +711,7 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
751
711
  {
752
712
  VALUE value, asn1data;
753
713
  unsigned char *p;
754
- int flag = 0;
714
+ long flag = 0;
755
715
 
756
716
  p = *pp;
757
717
 
@@ -798,22 +758,21 @@ int_ossl_asn1_decode0_prim(unsigned char **pp, long length, long hlen, int tag,
798
758
  *num_read = hlen + length;
799
759
 
800
760
  if (tc == sym_UNIVERSAL &&
801
- tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass) {
802
- VALUE klass = *ossl_asn1_info[tag].klass;
803
- VALUE args[4];
804
- args[0] = value;
805
- args[1] = INT2NUM(tag);
806
- args[2] = Qnil;
807
- args[3] = tc;
808
- asn1data = rb_obj_alloc(klass);
809
- ossl_asn1_initialize(4, args, asn1data);
810
- if(tag == V_ASN1_BIT_STRING){
811
- rb_ivar_set(asn1data, sivUNUSED_BITS, INT2NUM(flag));
812
- }
761
+ tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass) {
762
+ VALUE klass = *ossl_asn1_info[tag].klass;
763
+ if (tag == V_ASN1_EOC)
764
+ asn1data = rb_funcall(cASN1EndOfContent, rb_intern("new"), 0);
765
+ else {
766
+ VALUE args[4] = { value, INT2NUM(tag), Qnil, tc };
767
+ asn1data = rb_funcallv_public(klass, rb_intern("new"), 4, args);
768
+ }
769
+ if(tag == V_ASN1_BIT_STRING){
770
+ rb_ivar_set(asn1data, sivUNUSED_BITS, LONG2NUM(flag));
771
+ }
813
772
  }
814
773
  else {
815
- asn1data = rb_obj_alloc(cASN1Data);
816
- ossl_asn1data_initialize(asn1data, value, INT2NUM(tag), tc);
774
+ VALUE args[3] = { value, INT2NUM(tag), tc };
775
+ asn1data = rb_funcallv_public(cASN1Data, rb_intern("new"), 3, args);
817
776
  }
818
777
 
819
778
  return asn1data;
@@ -847,20 +806,20 @@ int_ossl_asn1_decode0_cons(unsigned char **pp, long max_len, long length,
847
806
  }
848
807
 
849
808
  if (tc == sym_UNIVERSAL) {
850
- VALUE args[4];
851
- if (tag == V_ASN1_SEQUENCE || tag == V_ASN1_SET)
852
- asn1data = rb_obj_alloc(*ossl_asn1_info[tag].klass);
853
- else
854
- asn1data = rb_obj_alloc(cASN1Constructive);
855
- args[0] = ary;
856
- args[1] = INT2NUM(tag);
857
- args[2] = Qnil;
858
- args[3] = tc;
859
- ossl_asn1_initialize(4, args, asn1data);
809
+ if (tag == V_ASN1_SEQUENCE) {
810
+ VALUE args[4] = { ary, INT2NUM(tag), Qnil, tc };
811
+ asn1data = rb_funcallv_public(cASN1Sequence, rb_intern("new"), 4, args);
812
+ } else if (tag == V_ASN1_SET) {
813
+ VALUE args[4] = { ary, INT2NUM(tag), Qnil, tc };
814
+ asn1data = rb_funcallv_public(cASN1Set, rb_intern("new"), 4, args);
815
+ } else {
816
+ VALUE args[4] = { ary, INT2NUM(tag), Qnil, tc };
817
+ asn1data = rb_funcallv_public(cASN1Constructive, rb_intern("new"), 4, args);
818
+ }
860
819
  }
861
820
  else {
862
- asn1data = rb_obj_alloc(cASN1Data);
863
- ossl_asn1data_initialize(asn1data, ary, INT2NUM(tag), tc);
821
+ VALUE args[3] = {ary, INT2NUM(tag), tc};
822
+ asn1data = rb_funcallv_public(cASN1Data, rb_intern("new"), 3, args);
864
823
  }
865
824
 
866
825
  if (indefinite)
@@ -1053,83 +1012,6 @@ ossl_asn1_decode_all(VALUE self, VALUE obj)
1053
1012
  return ary;
1054
1013
  }
1055
1014
 
1056
- /*
1057
- * call-seq:
1058
- * OpenSSL::ASN1::Primitive.new(value [, tag, tagging, tag_class ]) => Primitive
1059
- *
1060
- * _value_: is mandatory.
1061
- *
1062
- * _tag_: optional, may be specified for tagged values. If no _tag_ is
1063
- * specified, the UNIVERSAL tag corresponding to the Primitive sub-class
1064
- * is used by default.
1065
- *
1066
- * _tagging_: may be used as an encoding hint to encode a value either
1067
- * explicitly or implicitly, see ASN1 for possible values.
1068
- *
1069
- * _tag_class_: if _tag_ and _tagging_ are +nil+ then this is set to
1070
- * +:UNIVERSAL+ by default. If either _tag_ or _tagging_ are set then
1071
- * +:CONTEXT_SPECIFIC+ is used as the default. For possible values please
1072
- * cf. ASN1.
1073
- *
1074
- * == Example
1075
- * int = OpenSSL::ASN1::Integer.new(42)
1076
- * zero_tagged_int = OpenSSL::ASN1::Integer.new(42, 0, :IMPLICIT)
1077
- * private_explicit_zero_tagged_int = OpenSSL::ASN1::Integer.new(42, 0, :EXPLICIT, :PRIVATE)
1078
- */
1079
- static VALUE
1080
- ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
1081
- {
1082
- VALUE value, tag, tagging, tag_class;
1083
- int default_tag;
1084
-
1085
- rb_scan_args(argc, argv, "13", &value, &tag, &tagging, &tag_class);
1086
- default_tag = ossl_asn1_default_tag(self);
1087
-
1088
- if (default_tag == -1 || argc > 1) {
1089
- if(NIL_P(tag))
1090
- ossl_raise(eASN1Error, "must specify tag number");
1091
- if(!NIL_P(tagging) && !SYMBOL_P(tagging))
1092
- ossl_raise(eASN1Error, "invalid tagging method");
1093
- if(NIL_P(tag_class)) {
1094
- if (NIL_P(tagging))
1095
- tag_class = sym_UNIVERSAL;
1096
- else
1097
- tag_class = sym_CONTEXT_SPECIFIC;
1098
- }
1099
- if(!SYMBOL_P(tag_class))
1100
- ossl_raise(eASN1Error, "invalid tag class");
1101
- }
1102
- else{
1103
- tag = INT2NUM(default_tag);
1104
- tagging = Qnil;
1105
- tag_class = sym_UNIVERSAL;
1106
- }
1107
- ossl_asn1_set_tag(self, tag);
1108
- ossl_asn1_set_value(self, value);
1109
- ossl_asn1_set_tagging(self, tagging);
1110
- ossl_asn1_set_tag_class(self, tag_class);
1111
- ossl_asn1_set_indefinite_length(self, Qfalse);
1112
- if (default_tag == V_ASN1_BIT_STRING)
1113
- rb_ivar_set(self, sivUNUSED_BITS, INT2FIX(0));
1114
-
1115
- return self;
1116
- }
1117
-
1118
- static VALUE
1119
- ossl_asn1eoc_initialize(VALUE self) {
1120
- VALUE tag, tagging, tag_class, value;
1121
- tag = INT2FIX(0);
1122
- tagging = Qnil;
1123
- tag_class = sym_UNIVERSAL;
1124
- value = rb_str_new("", 0);
1125
- ossl_asn1_set_tag(self, tag);
1126
- ossl_asn1_set_value(self, value);
1127
- ossl_asn1_set_tagging(self, tagging);
1128
- ossl_asn1_set_tag_class(self, tag_class);
1129
- ossl_asn1_set_indefinite_length(self, Qfalse);
1130
- return self;
1131
- }
1132
-
1133
1015
  static VALUE
1134
1016
  ossl_asn1eoc_to_der(VALUE self)
1135
1017
  {
@@ -1168,9 +1050,12 @@ ossl_asn1prim_to_der(VALUE self)
1168
1050
  rb_jump_tag(state);
1169
1051
  }
1170
1052
  p0 = p1 = (unsigned char *)RSTRING_PTR(str);
1171
- i2d_ASN1_TYPE(asn1, &p0);
1053
+ if (i2d_ASN1_TYPE(asn1, &p0) < 0) {
1054
+ ASN1_TYPE_free(asn1);
1055
+ ossl_raise(eASN1Error, "i2d_ASN1_TYPE");
1056
+ }
1172
1057
  ASN1_TYPE_free(asn1);
1173
- assert(p0 - p1 == alllen);
1058
+ ossl_str_adjust(str, p0);
1174
1059
 
1175
1060
  /* Strip header since to_der_internal() wants only the payload */
1176
1061
  j = ASN1_get_object((const unsigned char **)&p1, &bodylen, &tag, &tc, alllen);
@@ -1218,27 +1103,6 @@ ossl_asn1cons_to_der(VALUE self)
1218
1103
  return to_der_internal(self, 1, indef_len, str);
1219
1104
  }
1220
1105
 
1221
- /*
1222
- * call-seq:
1223
- * asn1_ary.each { |asn1| block } => asn1_ary
1224
- *
1225
- * Calls the given block once for each element in self, passing that element
1226
- * as parameter _asn1_. If no block is given, an enumerator is returned
1227
- * instead.
1228
- *
1229
- * == Example
1230
- * asn1_ary.each do |asn1|
1231
- * puts asn1
1232
- * end
1233
- */
1234
- static VALUE
1235
- ossl_asn1cons_each(VALUE self)
1236
- {
1237
- rb_block_call(ossl_asn1_get_value(self), id_each, 0, 0, 0, 0);
1238
-
1239
- return self;
1240
- }
1241
-
1242
1106
  /*
1243
1107
  * call-seq:
1244
1108
  * OpenSSL::ASN1::ObjectId.register(object_id, short_name, long_name)
@@ -1368,7 +1232,7 @@ ossl_asn1obj_eq(VALUE self, VALUE other)
1368
1232
 
1369
1233
  #define OSSL_ASN1_IMPL_FACTORY_METHOD(klass) \
1370
1234
  static VALUE ossl_asn1_##klass(int argc, VALUE *argv, VALUE self)\
1371
- { return rb_funcall3(cASN1##klass, rb_intern("new"), argc, argv); }
1235
+ { return rb_funcallv_public(cASN1##klass, rb_intern("new"), argc, argv); }
1372
1236
 
1373
1237
  OSSL_ASN1_IMPL_FACTORY_METHOD(Boolean)
1374
1238
  OSSL_ASN1_IMPL_FACTORY_METHOD(Integer)
@@ -1654,42 +1518,6 @@ Init_ossl_asn1(void)
1654
1518
  * puts int2.value # => 1
1655
1519
  */
1656
1520
  cASN1Data = rb_define_class_under(mASN1, "ASN1Data", rb_cObject);
1657
- /*
1658
- * Carries the value of a ASN.1 type.
1659
- * Please confer Constructive and Primitive for the mappings between
1660
- * ASN.1 data types and Ruby classes.
1661
- */
1662
- rb_attr(cASN1Data, rb_intern("value"), 1, 1, 0);
1663
- /*
1664
- * An Integer representing the tag number of this ASN1Data. Never +nil+.
1665
- */
1666
- rb_attr(cASN1Data, rb_intern("tag"), 1, 1, 0);
1667
- /*
1668
- * A Symbol representing the tag class of this ASN1Data. Never +nil+.
1669
- * See ASN1Data for possible values.
1670
- */
1671
- rb_attr(cASN1Data, rb_intern("tag_class"), 1, 1, 0);
1672
- /*
1673
- * Never +nil+. A boolean value indicating whether the encoding uses
1674
- * indefinite length (in the case of parsing) or whether an indefinite
1675
- * length form shall be used (in the encoding case).
1676
- * In DER, every value uses definite length form. But in scenarios where
1677
- * large amounts of data need to be transferred it might be desirable to
1678
- * have some kind of streaming support available.
1679
- * For example, huge OCTET STRINGs are preferably sent in smaller-sized
1680
- * chunks, each at a time.
1681
- * This is possible in BER by setting the length bytes of an encoding
1682
- * to zero and by this indicating that the following value will be
1683
- * sent in chunks. Indefinite length encodings are always constructed.
1684
- * The end of such a stream of chunks is indicated by sending a EOC
1685
- * (End of Content) tag. SETs and SEQUENCEs may use an indefinite length
1686
- * encoding, but also primitive types such as e.g. OCTET STRINGS or
1687
- * BIT STRINGS may leverage this functionality (cf. ITU-T X.690).
1688
- */
1689
- rb_attr(cASN1Data, rb_intern("indefinite_length"), 1, 1, 0);
1690
- rb_define_alias(cASN1Data, "infinite_length", "indefinite_length");
1691
- rb_define_alias(cASN1Data, "infinite_length=", "indefinite_length=");
1692
- rb_define_method(cASN1Data, "initialize", ossl_asn1data_initialize, 3);
1693
1521
  rb_define_method(cASN1Data, "to_der", ossl_asn1data_to_der, 0);
1694
1522
 
1695
1523
  /* Document-class: OpenSSL::ASN1::Primitive
@@ -1757,16 +1585,6 @@ Init_ossl_asn1(void)
1757
1585
  * prim_zero_tagged_explicit = <class>.new(value, 0, :EXPLICIT)
1758
1586
  */
1759
1587
  cASN1Primitive = rb_define_class_under(mASN1, "Primitive", cASN1Data);
1760
- /*
1761
- * May be used as a hint for encoding a value either implicitly or
1762
- * explicitly by setting it either to +:IMPLICIT+ or to +:EXPLICIT+.
1763
- * _tagging_ is not set when a ASN.1 structure is parsed using
1764
- * OpenSSL::ASN1.decode.
1765
- */
1766
- rb_attr(cASN1Primitive, rb_intern("tagging"), 1, 1, Qtrue);
1767
- rb_undef_method(cASN1Primitive, "indefinite_length=");
1768
- rb_undef_method(cASN1Primitive, "infinite_length=");
1769
- rb_define_method(cASN1Primitive, "initialize", ossl_asn1_initialize, -1);
1770
1588
  rb_define_method(cASN1Primitive, "to_der", ossl_asn1prim_to_der, 0);
1771
1589
 
1772
1590
  /* Document-class: OpenSSL::ASN1::Constructive
@@ -1797,17 +1615,7 @@ Init_ossl_asn1(void)
1797
1615
  * set = OpenSSL::ASN1::Set.new( [ int, str ] )
1798
1616
  */
1799
1617
  cASN1Constructive = rb_define_class_under(mASN1,"Constructive", cASN1Data);
1800
- rb_include_module(cASN1Constructive, rb_mEnumerable);
1801
- /*
1802
- * May be used as a hint for encoding a value either implicitly or
1803
- * explicitly by setting it either to +:IMPLICIT+ or to +:EXPLICIT+.
1804
- * _tagging_ is not set when a ASN.1 structure is parsed using
1805
- * OpenSSL::ASN1.decode.
1806
- */
1807
- rb_attr(cASN1Constructive, rb_intern("tagging"), 1, 1, Qtrue);
1808
- rb_define_method(cASN1Constructive, "initialize", ossl_asn1_initialize, -1);
1809
1618
  rb_define_method(cASN1Constructive, "to_der", ossl_asn1cons_to_der, 0);
1810
- rb_define_method(cASN1Constructive, "each", ossl_asn1cons_each, 0);
1811
1619
 
1812
1620
  #define OSSL_ASN1_DEFINE_CLASS(name, super) \
1813
1621
  do{\
@@ -1856,13 +1664,10 @@ do{\
1856
1664
  rb_define_alias(cASN1ObjectId, "short_name", "sn");
1857
1665
  rb_define_alias(cASN1ObjectId, "long_name", "ln");
1858
1666
  rb_define_method(cASN1ObjectId, "==", ossl_asn1obj_eq, 1);
1859
- rb_attr(cASN1BitString, rb_intern("unused_bits"), 1, 1, 0);
1860
1667
 
1861
- rb_define_method(cASN1EndOfContent, "initialize", ossl_asn1eoc_initialize, 0);
1862
1668
  rb_define_method(cASN1EndOfContent, "to_der", ossl_asn1eoc_to_der, 0);
1863
1669
 
1864
1670
  class_tag_map = rb_hash_new();
1865
- rb_gc_register_mark_object(class_tag_map);
1866
1671
  rb_hash_aset(class_tag_map, cASN1EndOfContent, INT2NUM(V_ASN1_EOC));
1867
1672
  rb_hash_aset(class_tag_map, cASN1Boolean, INT2NUM(V_ASN1_BOOLEAN));
1868
1673
  rb_hash_aset(class_tag_map, cASN1Integer, INT2NUM(V_ASN1_INTEGER));
@@ -1886,6 +1691,5 @@ do{\
1886
1691
  rb_hash_aset(class_tag_map, cASN1GeneralString, INT2NUM(V_ASN1_GENERALSTRING));
1887
1692
  rb_hash_aset(class_tag_map, cASN1UniversalString, INT2NUM(V_ASN1_UNIVERSALSTRING));
1888
1693
  rb_hash_aset(class_tag_map, cASN1BMPString, INT2NUM(V_ASN1_BMPSTRING));
1889
-
1890
- id_each = rb_intern_const("each");
1694
+ rb_define_const(mASN1, "CLASS_TAG_MAP", class_tag_map);
1891
1695
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_ASN1_H_)
11
11
  #define _OSSL_ASN1_H_
@@ -38,24 +38,6 @@ extern VALUE mASN1;
38
38
  extern VALUE eASN1Error;
39
39
 
40
40
  extern VALUE cASN1Data;
41
- extern VALUE cASN1Primitive;
42
- extern VALUE cASN1Constructive;
43
-
44
- extern VALUE cASN1Boolean; /* BOOLEAN */
45
- extern VALUE cASN1Integer, cASN1Enumerated; /* INTEGER */
46
- extern VALUE cASN1BitString; /* BIT STRING */
47
- extern VALUE cASN1OctetString, cASN1UTF8String; /* STRINGs */
48
- extern VALUE cASN1NumericString, cASN1PrintableString;
49
- extern VALUE cASN1T61String, cASN1VideotexString;
50
- extern VALUE cASN1IA5String, cASN1GraphicString;
51
- extern VALUE cASN1ISO64String, cASN1GeneralString;
52
- extern VALUE cASN1UniversalString, cASN1BMPString;
53
- extern VALUE cASN1Null; /* NULL */
54
- extern VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
55
- extern VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
56
- extern VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */
57
-
58
- ASN1_TYPE *ossl_asn1_get_asn1type(VALUE);
59
41
 
60
42
  void Init_ossl_asn1(void);
61
43
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_BIO_H_)
11
11
  #define _OSSL_BIO_H_