rubysl-openssl 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -6
  3. data/ext/rubysl/openssl/.gitignore +3 -0
  4. data/ext/rubysl/openssl/deprecation.rb +21 -0
  5. data/ext/rubysl/openssl/extconf.rb +45 -32
  6. data/ext/rubysl/openssl/openssl_missing.c +20 -7
  7. data/ext/rubysl/openssl/openssl_missing.h +22 -15
  8. data/ext/rubysl/openssl/ossl.c +610 -61
  9. data/ext/rubysl/openssl/ossl.h +31 -17
  10. data/ext/rubysl/openssl/ossl_asn1.c +974 -183
  11. data/ext/rubysl/openssl/ossl_asn1.h +3 -3
  12. data/ext/rubysl/openssl/ossl_bio.c +4 -3
  13. data/ext/rubysl/openssl/ossl_bio.h +1 -1
  14. data/ext/rubysl/openssl/ossl_bn.c +32 -28
  15. data/ext/rubysl/openssl/ossl_bn.h +1 -1
  16. data/ext/rubysl/openssl/ossl_cipher.c +494 -93
  17. data/ext/rubysl/openssl/ossl_cipher.h +1 -1
  18. data/ext/rubysl/openssl/ossl_config.c +4 -5
  19. data/ext/rubysl/openssl/ossl_config.h +1 -1
  20. data/ext/rubysl/openssl/ossl_digest.c +206 -24
  21. data/ext/rubysl/openssl/ossl_digest.h +1 -1
  22. data/ext/rubysl/openssl/ossl_engine.c +48 -26
  23. data/ext/rubysl/openssl/ossl_engine.h +1 -1
  24. data/ext/rubysl/openssl/ossl_hmac.c +40 -38
  25. data/ext/rubysl/openssl/ossl_hmac.h +1 -1
  26. data/ext/rubysl/openssl/ossl_ns_spki.c +157 -25
  27. data/ext/rubysl/openssl/ossl_ns_spki.h +1 -1
  28. data/ext/rubysl/openssl/ossl_ocsp.c +57 -40
  29. data/ext/rubysl/openssl/ossl_ocsp.h +1 -1
  30. data/ext/rubysl/openssl/ossl_pkcs12.c +15 -13
  31. data/ext/rubysl/openssl/ossl_pkcs12.h +1 -1
  32. data/ext/rubysl/openssl/ossl_pkcs5.c +108 -18
  33. data/ext/rubysl/openssl/ossl_pkcs7.c +44 -37
  34. data/ext/rubysl/openssl/ossl_pkcs7.h +1 -1
  35. data/ext/rubysl/openssl/ossl_pkey.c +211 -15
  36. data/ext/rubysl/openssl/ossl_pkey.h +19 -9
  37. data/ext/rubysl/openssl/ossl_pkey_dh.c +180 -47
  38. data/ext/rubysl/openssl/ossl_pkey_dsa.c +184 -47
  39. data/ext/rubysl/openssl/ossl_pkey_ec.c +177 -93
  40. data/ext/rubysl/openssl/ossl_pkey_rsa.c +209 -102
  41. data/ext/rubysl/openssl/ossl_rand.c +15 -15
  42. data/ext/rubysl/openssl/ossl_rand.h +1 -1
  43. data/ext/rubysl/openssl/ossl_ssl.c +939 -192
  44. data/ext/rubysl/openssl/ossl_ssl.h +6 -6
  45. data/ext/rubysl/openssl/ossl_ssl_session.c +78 -62
  46. data/ext/rubysl/openssl/ossl_version.h +2 -2
  47. data/ext/rubysl/openssl/ossl_x509.c +1 -1
  48. data/ext/rubysl/openssl/ossl_x509.h +1 -1
  49. data/ext/rubysl/openssl/ossl_x509attr.c +20 -19
  50. data/ext/rubysl/openssl/ossl_x509cert.c +169 -67
  51. data/ext/rubysl/openssl/ossl_x509crl.c +41 -39
  52. data/ext/rubysl/openssl/ossl_x509ext.c +51 -38
  53. data/ext/rubysl/openssl/ossl_x509name.c +139 -29
  54. data/ext/rubysl/openssl/ossl_x509req.c +42 -40
  55. data/ext/rubysl/openssl/ossl_x509revoked.c +20 -20
  56. data/ext/rubysl/openssl/ossl_x509store.c +99 -47
  57. data/ext/rubysl/openssl/ruby_missing.h +3 -16
  58. data/lib/openssl/bn.rb +19 -19
  59. data/lib/openssl/buffering.rb +222 -14
  60. data/lib/openssl/cipher.rb +20 -20
  61. data/lib/openssl/config.rb +1 -4
  62. data/lib/openssl/digest.rb +47 -19
  63. data/lib/openssl/ssl.rb +197 -1
  64. data/lib/openssl/x509.rb +162 -1
  65. data/lib/rubysl/openssl.rb +4 -8
  66. data/lib/rubysl/openssl/version.rb +1 -1
  67. data/rubysl-openssl.gemspec +1 -2
  68. metadata +16 -34
  69. data/ext/rubysl/openssl/extconf.h +0 -50
  70. data/lib/openssl/net/ftptls.rb +0 -53
  71. data/lib/openssl/net/telnets.rb +0 -251
  72. data/lib/openssl/pkcs7.rb +0 -25
  73. data/lib/openssl/ssl-internal.rb +0 -187
  74. data/lib/openssl/x509-internal.rb +0 -153
@@ -1,5 +1,5 @@
1
1
  /*
2
- * $Id: ossl_x509crl.c 28367 2010-06-21 09:18:59Z shyouhei $
2
+ * $Id$
3
3
  * 'OpenSSL for Ruby' project
4
4
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
5
  * All rights reserved.
@@ -11,20 +11,20 @@
11
11
  #include "ossl.h"
12
12
 
13
13
  #define WrapX509CRL(klass, obj, crl) do { \
14
- if (!crl) { \
14
+ if (!(crl)) { \
15
15
  ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
16
16
  } \
17
- obj = Data_Wrap_Struct(klass, 0, X509_CRL_free, crl); \
17
+ (obj) = Data_Wrap_Struct((klass), 0, X509_CRL_free, (crl)); \
18
18
  } while (0)
19
19
  #define GetX509CRL(obj, crl) do { \
20
- Data_Get_Struct(obj, X509_CRL, crl); \
21
- if (!crl) { \
20
+ Data_Get_Struct((obj), X509_CRL, (crl)); \
21
+ if (!(crl)) { \
22
22
  ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
23
23
  } \
24
24
  } while (0)
25
25
  #define SafeGetX509CRL(obj, crl) do { \
26
- OSSL_Check_Kind(obj, cX509CRL); \
27
- GetX509CRL(obj, crl); \
26
+ OSSL_Check_Kind((obj), cX509CRL); \
27
+ GetX509CRL((obj), (crl)); \
28
28
  } while (0)
29
29
 
30
30
  /*
@@ -66,14 +66,14 @@ ossl_x509crl_new(X509_CRL *crl)
66
66
  tmp = crl ? X509_CRL_dup(crl) : X509_CRL_new();
67
67
  if(!tmp) ossl_raise(eX509CRLError, NULL);
68
68
  WrapX509CRL(cX509CRL, obj, tmp);
69
-
69
+
70
70
  return obj;
71
71
  }
72
72
 
73
73
  /*
74
74
  * PRIVATE
75
75
  */
76
- static VALUE
76
+ static VALUE
77
77
  ossl_x509crl_alloc(VALUE klass)
78
78
  {
79
79
  X509_CRL *crl;
@@ -87,11 +87,11 @@ ossl_x509crl_alloc(VALUE klass)
87
87
  return obj;
88
88
  }
89
89
 
90
- static VALUE
90
+ static VALUE
91
91
  ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
92
92
  {
93
93
  BIO *in;
94
- X509_CRL *crl;
94
+ X509_CRL *crl, *x = DATA_PTR(self);
95
95
  VALUE arg;
96
96
 
97
97
  if (rb_scan_args(argc, argv, "01", &arg) == 0) {
@@ -99,10 +99,12 @@ ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
99
99
  }
100
100
  arg = ossl_to_der_if_possible(arg);
101
101
  in = ossl_obj2bio(arg);
102
- crl = PEM_read_bio_X509_CRL(in, (X509_CRL **)&DATA_PTR(self), NULL, NULL);
102
+ crl = PEM_read_bio_X509_CRL(in, &x, NULL, NULL);
103
+ DATA_PTR(self) = x;
103
104
  if (!crl) {
104
- BIO_reset(in);
105
- crl = d2i_X509_CRL_bio(in, (X509_CRL **)&DATA_PTR(self));
105
+ OSSL_BIO_reset(in);
106
+ crl = d2i_X509_CRL_bio(in, &x);
107
+ DATA_PTR(self) = x;
106
108
  }
107
109
  BIO_free(in);
108
110
  if (!crl) ossl_raise(eX509CRLError, NULL);
@@ -114,7 +116,7 @@ static VALUE
114
116
  ossl_x509crl_copy(VALUE self, VALUE other)
115
117
  {
116
118
  X509_CRL *a, *b, *crl;
117
-
119
+
118
120
  rb_check_frozen(self);
119
121
  if (self == other) return self;
120
122
  GetX509CRL(self, a);
@@ -128,7 +130,7 @@ ossl_x509crl_copy(VALUE self, VALUE other)
128
130
  return self;
129
131
  }
130
132
 
131
- static VALUE
133
+ static VALUE
132
134
  ossl_x509crl_get_version(VALUE self)
133
135
  {
134
136
  X509_CRL *crl;
@@ -140,7 +142,7 @@ ossl_x509crl_get_version(VALUE self)
140
142
  return LONG2NUM(ver);
141
143
  }
142
144
 
143
- static VALUE
145
+ static VALUE
144
146
  ossl_x509crl_set_version(VALUE self, VALUE version)
145
147
  {
146
148
  X509_CRL *crl;
@@ -157,7 +159,7 @@ ossl_x509crl_set_version(VALUE self, VALUE version)
157
159
  return version;
158
160
  }
159
161
 
160
- static VALUE
162
+ static VALUE
161
163
  ossl_x509crl_get_signature_algorithm(VALUE self)
162
164
  {
163
165
  X509_CRL *crl;
@@ -179,7 +181,7 @@ ossl_x509crl_get_signature_algorithm(VALUE self)
179
181
  return str;
180
182
  }
181
183
 
182
- static VALUE
184
+ static VALUE
183
185
  ossl_x509crl_get_issuer(VALUE self)
184
186
  {
185
187
  X509_CRL *crl;
@@ -189,7 +191,7 @@ ossl_x509crl_get_issuer(VALUE self)
189
191
  return ossl_x509name_new(X509_CRL_get_issuer(crl)); /* NO DUP - don't free */
190
192
  }
191
193
 
192
- static VALUE
194
+ static VALUE
193
195
  ossl_x509crl_set_issuer(VALUE self, VALUE issuer)
194
196
  {
195
197
  X509_CRL *crl;
@@ -202,7 +204,7 @@ ossl_x509crl_set_issuer(VALUE self, VALUE issuer)
202
204
  return issuer;
203
205
  }
204
206
 
205
- static VALUE
207
+ static VALUE
206
208
  ossl_x509crl_get_last_update(VALUE self)
207
209
  {
208
210
  X509_CRL *crl;
@@ -212,7 +214,7 @@ ossl_x509crl_get_last_update(VALUE self)
212
214
  return asn1time_to_time(X509_CRL_get_lastUpdate(crl));
213
215
  }
214
216
 
215
- static VALUE
217
+ static VALUE
216
218
  ossl_x509crl_set_last_update(VALUE self, VALUE time)
217
219
  {
218
220
  X509_CRL *crl;
@@ -227,7 +229,7 @@ ossl_x509crl_set_last_update(VALUE self, VALUE time)
227
229
  return time;
228
230
  }
229
231
 
230
- static VALUE
232
+ static VALUE
231
233
  ossl_x509crl_get_next_update(VALUE self)
232
234
  {
233
235
  X509_CRL *crl;
@@ -237,7 +239,7 @@ ossl_x509crl_get_next_update(VALUE self)
237
239
  return asn1time_to_time(X509_CRL_get_nextUpdate(crl));
238
240
  }
239
241
 
240
- static VALUE
242
+ static VALUE
241
243
  ossl_x509crl_set_next_update(VALUE self, VALUE time)
242
244
  {
243
245
  X509_CRL *crl;
@@ -278,7 +280,7 @@ ossl_x509crl_get_revoked(VALUE self)
278
280
  return ary;
279
281
  }
280
282
 
281
- static VALUE
283
+ static VALUE
282
284
  ossl_x509crl_set_revoked(VALUE self, VALUE ary)
283
285
  {
284
286
  X509_CRL *crl;
@@ -304,7 +306,7 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
304
306
  return ary;
305
307
  }
306
308
 
307
- static VALUE
309
+ static VALUE
308
310
  ossl_x509crl_add_revoked(VALUE self, VALUE revoked)
309
311
  {
310
312
  X509_CRL *crl;
@@ -320,7 +322,7 @@ ossl_x509crl_add_revoked(VALUE self, VALUE revoked)
320
322
  return revoked;
321
323
  }
322
324
 
323
- static VALUE
325
+ static VALUE
324
326
  ossl_x509crl_sign(VALUE self, VALUE key, VALUE digest)
325
327
  {
326
328
  X509_CRL *crl;
@@ -337,7 +339,7 @@ ossl_x509crl_sign(VALUE self, VALUE key, VALUE digest)
337
339
  return self;
338
340
  }
339
341
 
340
- static VALUE
342
+ static VALUE
341
343
  ossl_x509crl_verify(VALUE self, VALUE key)
342
344
  {
343
345
  X509_CRL *crl;
@@ -354,7 +356,7 @@ ossl_x509crl_verify(VALUE self, VALUE key)
354
356
  return Qfalse;
355
357
  }
356
358
 
357
- static VALUE
359
+ static VALUE
358
360
  ossl_x509crl_to_der(VALUE self)
359
361
  {
360
362
  X509_CRL *crl;
@@ -377,7 +379,7 @@ ossl_x509crl_to_der(VALUE self)
377
379
  return str;
378
380
  }
379
381
 
380
- static VALUE
382
+ static VALUE
381
383
  ossl_x509crl_to_pem(VALUE self)
382
384
  {
383
385
  X509_CRL *crl;
@@ -400,7 +402,7 @@ ossl_x509crl_to_pem(VALUE self)
400
402
  return str;
401
403
  }
402
404
 
403
- static VALUE
405
+ static VALUE
404
406
  ossl_x509crl_to_text(VALUE self)
405
407
  {
406
408
  X509_CRL *crl;
@@ -419,14 +421,14 @@ ossl_x509crl_to_text(VALUE self)
419
421
  BIO_get_mem_ptr(out, &buf);
420
422
  str = rb_str_new(buf->data, buf->length);
421
423
  BIO_free(out);
422
-
424
+
423
425
  return str;
424
426
  }
425
427
 
426
428
  /*
427
429
  * Gets X509v3 extensions as array of X509Ext objects
428
430
  */
429
- static VALUE
431
+ static VALUE
430
432
  ossl_x509crl_get_extensions(VALUE self)
431
433
  {
432
434
  X509_CRL *crl;
@@ -452,13 +454,13 @@ ossl_x509crl_get_extensions(VALUE self)
452
454
  /*
453
455
  * Sets X509_EXTENSIONs
454
456
  */
455
- static VALUE
457
+ static VALUE
456
458
  ossl_x509crl_set_extensions(VALUE self, VALUE ary)
457
459
  {
458
460
  X509_CRL *crl;
459
461
  X509_EXTENSION *ext;
460
462
  int i;
461
-
463
+
462
464
  Check_Type(ary, T_ARRAY);
463
465
  /* All ary members should be X509 Extensions */
464
466
  for (i=0; i<RARRAY_LEN(ary); i++) {
@@ -479,7 +481,7 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
479
481
  return ary;
480
482
  }
481
483
 
482
- static VALUE
484
+ static VALUE
483
485
  ossl_x509crl_add_extension(VALUE self, VALUE extension)
484
486
  {
485
487
  X509_CRL *crl;
@@ -499,17 +501,17 @@ ossl_x509crl_add_extension(VALUE self, VALUE extension)
499
501
  /*
500
502
  * INIT
501
503
  */
502
- void
504
+ void
503
505
  Init_ossl_x509crl()
504
506
  {
505
507
  eX509CRLError = rb_define_class_under(mX509, "CRLError", eOSSLError);
506
508
 
507
509
  cX509CRL = rb_define_class_under(mX509, "CRL", rb_cObject);
508
-
510
+
509
511
  rb_define_alloc_func(cX509CRL, ossl_x509crl_alloc);
510
512
  rb_define_method(cX509CRL, "initialize", ossl_x509crl_initialize, -1);
511
513
  rb_define_copy_func(cX509CRL, ossl_x509crl_copy);
512
-
514
+
513
515
  rb_define_method(cX509CRL, "version", ossl_x509crl_get_version, 0);
514
516
  rb_define_method(cX509CRL, "version=", ossl_x509crl_set_version, 1);
515
517
  rb_define_method(cX509CRL, "signature_algorithm", ossl_x509crl_get_signature_algorithm, 0);
@@ -11,30 +11,30 @@
11
11
  #include "ossl.h"
12
12
 
13
13
  #define WrapX509Ext(klass, obj, ext) do { \
14
- if (!ext) { \
14
+ if (!(ext)) { \
15
15
  ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
16
16
  } \
17
- obj = Data_Wrap_Struct(klass, 0, X509_EXTENSION_free, ext); \
17
+ (obj) = Data_Wrap_Struct((klass), 0, X509_EXTENSION_free, (ext)); \
18
18
  } while (0)
19
19
  #define GetX509Ext(obj, ext) do { \
20
- Data_Get_Struct(obj, X509_EXTENSION, ext); \
21
- if (!ext) { \
20
+ Data_Get_Struct((obj), X509_EXTENSION, (ext)); \
21
+ if (!(ext)) { \
22
22
  ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
23
23
  } \
24
24
  } while (0)
25
25
  #define SafeGetX509Ext(obj, ext) do { \
26
- OSSL_Check_Kind(obj, cX509Ext); \
27
- GetX509Ext(obj, ext); \
26
+ OSSL_Check_Kind((obj), cX509Ext); \
27
+ GetX509Ext((obj), (ext)); \
28
28
  } while (0)
29
29
  #define MakeX509ExtFactory(klass, obj, ctx) do { \
30
- if (!(ctx = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
30
+ if (!((ctx) = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
31
31
  ossl_raise(rb_eRuntimeError, "CTX wasn't allocated!"); \
32
- X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, 0); \
33
- obj = Data_Wrap_Struct(klass, 0, ossl_x509extfactory_free, ctx); \
32
+ X509V3_set_ctx((ctx), NULL, NULL, NULL, NULL, 0); \
33
+ (obj) = Data_Wrap_Struct((klass), 0, ossl_x509extfactory_free, (ctx)); \
34
34
  } while (0)
35
35
  #define GetX509ExtFactory(obj, ctx) do { \
36
- Data_Get_Struct(obj, X509V3_CTX, ctx); \
37
- if (!ctx) { \
36
+ Data_Get_Struct((obj), X509V3_CTX, (ctx)); \
37
+ if (!(ctx)) { \
38
38
  ossl_raise(rb_eRuntimeError, "CTX wasn't initialized!"); \
39
39
  } \
40
40
  } while (0)
@@ -49,7 +49,7 @@ VALUE eX509ExtError;
49
49
  /*
50
50
  * Public
51
51
  */
52
- VALUE
52
+ VALUE
53
53
  ossl_x509ext_new(X509_EXTENSION *ext)
54
54
  {
55
55
  X509_EXTENSION *new;
@@ -64,7 +64,7 @@ ossl_x509ext_new(X509_EXTENSION *ext)
64
64
  ossl_raise(eX509ExtError, NULL);
65
65
  }
66
66
  WrapX509Ext(cX509Ext, obj, new);
67
-
67
+
68
68
  return obj;
69
69
  }
70
70
 
@@ -103,18 +103,19 @@ ossl_x509extfactory_free(X509V3_CTX *ctx)
103
103
  OPENSSL_free(ctx);
104
104
  }
105
105
 
106
- static VALUE
106
+ static VALUE
107
107
  ossl_x509extfactory_alloc(VALUE klass)
108
108
  {
109
109
  X509V3_CTX *ctx;
110
110
  VALUE obj;
111
111
 
112
112
  MakeX509ExtFactory(klass, obj, ctx);
113
+ rb_iv_set(obj, "@config", Qnil);
113
114
 
114
115
  return obj;
115
116
  }
116
117
 
117
- static VALUE
118
+ static VALUE
118
119
  ossl_x509extfactory_set_issuer_cert(VALUE self, VALUE cert)
119
120
  {
120
121
  X509V3_CTX *ctx;
@@ -126,7 +127,7 @@ ossl_x509extfactory_set_issuer_cert(VALUE self, VALUE cert)
126
127
  return cert;
127
128
  }
128
129
 
129
- static VALUE
130
+ static VALUE
130
131
  ossl_x509extfactory_set_subject_cert(VALUE self, VALUE cert)
131
132
  {
132
133
  X509V3_CTX *ctx;
@@ -138,7 +139,7 @@ ossl_x509extfactory_set_subject_cert(VALUE self, VALUE cert)
138
139
  return cert;
139
140
  }
140
141
 
141
- static VALUE
142
+ static VALUE
142
143
  ossl_x509extfactory_set_subject_req(VALUE self, VALUE req)
143
144
  {
144
145
  X509V3_CTX *ctx;
@@ -150,7 +151,7 @@ ossl_x509extfactory_set_subject_req(VALUE self, VALUE req)
150
151
  return req;
151
152
  }
152
153
 
153
- static VALUE
154
+ static VALUE
154
155
  ossl_x509extfactory_set_crl(VALUE self, VALUE crl)
155
156
  {
156
157
  X509V3_CTX *ctx;
@@ -162,10 +163,10 @@ ossl_x509extfactory_set_crl(VALUE self, VALUE crl)
162
163
  return crl;
163
164
  }
164
165
 
166
+ #ifdef HAVE_X509V3_SET_NCONF
165
167
  static VALUE
166
168
  ossl_x509extfactory_set_config(VALUE self, VALUE config)
167
169
  {
168
- #ifdef HAVE_X509V3_SET_NCONF
169
170
  X509V3_CTX *ctx;
170
171
  CONF *conf;
171
172
 
@@ -175,17 +176,17 @@ ossl_x509extfactory_set_config(VALUE self, VALUE config)
175
176
  X509V3_set_nconf(ctx, conf);
176
177
 
177
178
  return config;
179
+ }
178
180
  #else
179
- rb_notimplement();
181
+ #define ossl_x509extfactory_set_config rb_f_notimplement
180
182
  #endif
181
- }
182
183
 
183
- static VALUE
184
+ static VALUE
184
185
  ossl_x509extfactory_initialize(int argc, VALUE *argv, VALUE self)
185
186
  {
186
187
  /*X509V3_CTX *ctx;*/
187
188
  VALUE issuer_cert, subject_cert, subject_req, crl;
188
-
189
+
189
190
  /*GetX509ExtFactory(self, ctx);*/
190
191
 
191
192
  rb_scan_args(argc, argv, "04",
@@ -198,7 +199,6 @@ ossl_x509extfactory_initialize(int argc, VALUE *argv, VALUE self)
198
199
  ossl_x509extfactory_set_subject_req(self, subject_req);
199
200
  if (!NIL_P(crl))
200
201
  ossl_x509extfactory_set_crl(self, crl);
201
- rb_iv_set(self, "@config", Qnil);
202
202
 
203
203
  return self;
204
204
  }
@@ -211,7 +211,7 @@ ossl_x509extfactory_initialize(int argc, VALUE *argv, VALUE self)
211
211
  * ["ln", "critical,value"] or the same for sn
212
212
  * ["ln", "value"] => not critical
213
213
  */
214
- static VALUE
214
+ static VALUE
215
215
  ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
216
216
  {
217
217
  X509V3_CTX *ctx;
@@ -270,20 +270,33 @@ ossl_x509ext_alloc(VALUE klass)
270
270
  return obj;
271
271
  }
272
272
 
273
+ /*
274
+ * call-seq:
275
+ * OpenSSL::X509::Extension.new asn1
276
+ * OpenSSL::X509::Extension.new name, value
277
+ * OpenSSL::X509::Extension.new name, value, critical
278
+ *
279
+ * Creates an X509 extension.
280
+ *
281
+ * The extension may be created from +asn1+ data or from an extension +name+
282
+ * and +value+. The +name+ may be either an OID or an extension name. If
283
+ * +critical+ is true the extension is marked critical.
284
+ */
273
285
  static VALUE
274
286
  ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
275
287
  {
276
288
  VALUE oid, value, critical;
277
289
  const unsigned char *p;
278
- X509_EXTENSION *ext;
290
+ X509_EXTENSION *ext, *x;
279
291
 
280
292
  GetX509Ext(self, ext);
281
293
  if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){
282
294
  oid = ossl_to_der_if_possible(oid);
283
295
  StringValue(oid);
284
- p = (const unsigned char*) RSTRING_PTR(oid);
285
- if(!d2i_X509_EXTENSION((X509_EXTENSION**)&DATA_PTR(self),
286
- &p, RSTRING_LEN(oid)))
296
+ p = (unsigned char *)RSTRING_PTR(oid);
297
+ x = d2i_X509_EXTENSION(&ext, &p, RSTRING_LEN(oid));
298
+ DATA_PTR(self) = ext;
299
+ if(!x)
287
300
  ossl_raise(eX509ExtError, NULL);
288
301
  return self;
289
302
  }
@@ -324,11 +337,11 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
324
337
  ossl_raise(eX509ExtError, "malloc error");
325
338
  memcpy(s, RSTRING_PTR(data), RSTRING_LEN(data));
326
339
  if(!(asn1s = ASN1_OCTET_STRING_new())){
327
- OPENSSL_free(s);
340
+ OPENSSL_free(s);
328
341
  ossl_raise(eX509ExtError, NULL);
329
342
  }
330
- if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LEN(data))){
331
- OPENSSL_free(s);
343
+ if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LENINT(data))){
344
+ OPENSSL_free(s);
332
345
  ASN1_OCTET_STRING_free(asn1s);
333
346
  ossl_raise(eX509ExtError, NULL);
334
347
  }
@@ -350,7 +363,7 @@ ossl_x509ext_set_critical(VALUE self, VALUE flag)
350
363
  return flag;
351
364
  }
352
365
 
353
- static VALUE
366
+ static VALUE
354
367
  ossl_x509ext_get_oid(VALUE obj)
355
368
  {
356
369
  X509_EXTENSION *ext;
@@ -411,7 +424,7 @@ ossl_x509ext_to_der(VALUE obj)
411
424
  if((len = i2d_X509_EXTENSION(ext, NULL)) <= 0)
412
425
  ossl_raise(eX509ExtError, NULL);
413
426
  str = rb_str_new(0, len);
414
- p = RSTRING_PTR(str);
427
+ p = (unsigned char *)RSTRING_PTR(str);
415
428
  if(i2d_X509_EXTENSION(ext, &p) < 0)
416
429
  ossl_raise(eX509ExtError, NULL);
417
430
  ossl_str_adjust(str, p);
@@ -426,12 +439,12 @@ void
426
439
  Init_ossl_x509ext()
427
440
  {
428
441
  eX509ExtError = rb_define_class_under(mX509, "ExtensionError", eOSSLError);
429
-
442
+
430
443
  cX509ExtFactory = rb_define_class_under(mX509, "ExtensionFactory", rb_cObject);
431
-
444
+
432
445
  rb_define_alloc_func(cX509ExtFactory, ossl_x509extfactory_alloc);
433
446
  rb_define_method(cX509ExtFactory, "initialize", ossl_x509extfactory_initialize, -1);
434
-
447
+
435
448
  rb_attr(cX509ExtFactory, rb_intern("issuer_certificate"), 1, 0, Qfalse);
436
449
  rb_attr(cX509ExtFactory, rb_intern("subject_certificate"), 1, 0, Qfalse);
437
450
  rb_attr(cX509ExtFactory, rb_intern("subject_request"), 1, 0, Qfalse);
@@ -444,7 +457,7 @@ Init_ossl_x509ext()
444
457
  rb_define_method(cX509ExtFactory, "crl=", ossl_x509extfactory_set_crl, 1);
445
458
  rb_define_method(cX509ExtFactory, "config=", ossl_x509extfactory_set_config, 1);
446
459
  rb_define_method(cX509ExtFactory, "create_ext", ossl_x509extfactory_create_ext, -1);
447
-
460
+
448
461
  cX509Ext = rb_define_class_under(mX509, "Extension", rb_cObject);
449
462
  rb_define_alloc_func(cX509Ext, ossl_x509ext_alloc);
450
463
  rb_define_method(cX509Ext, "initialize", ossl_x509ext_initialize, -1);