openssl-custom 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/BSDL +22 -0
  3. data/CONTRIBUTING.md +132 -0
  4. data/History.md +485 -0
  5. data/LICENSE.txt +56 -0
  6. data/README.md +66 -0
  7. data/ext/openssl/extconf.rb +190 -0
  8. data/ext/openssl/openssl_missing.c +106 -0
  9. data/ext/openssl/openssl_missing.h +257 -0
  10. data/ext/openssl/ossl.c +1282 -0
  11. data/ext/openssl/ossl.h +181 -0
  12. data/ext/openssl/ossl_asn1.c +1878 -0
  13. data/ext/openssl/ossl_asn1.h +62 -0
  14. data/ext/openssl/ossl_bio.c +42 -0
  15. data/ext/openssl/ossl_bio.h +16 -0
  16. data/ext/openssl/ossl_bn.c +1270 -0
  17. data/ext/openssl/ossl_bn.h +26 -0
  18. data/ext/openssl/ossl_cipher.c +1075 -0
  19. data/ext/openssl/ossl_cipher.h +20 -0
  20. data/ext/openssl/ossl_config.c +89 -0
  21. data/ext/openssl/ossl_config.h +19 -0
  22. data/ext/openssl/ossl_digest.c +425 -0
  23. data/ext/openssl/ossl_digest.h +20 -0
  24. data/ext/openssl/ossl_engine.c +567 -0
  25. data/ext/openssl/ossl_engine.h +19 -0
  26. data/ext/openssl/ossl_hmac.c +389 -0
  27. data/ext/openssl/ossl_hmac.h +18 -0
  28. data/ext/openssl/ossl_kdf.c +303 -0
  29. data/ext/openssl/ossl_kdf.h +6 -0
  30. data/ext/openssl/ossl_ns_spki.c +405 -0
  31. data/ext/openssl/ossl_ns_spki.h +19 -0
  32. data/ext/openssl/ossl_ocsp.c +2013 -0
  33. data/ext/openssl/ossl_ocsp.h +23 -0
  34. data/ext/openssl/ossl_pkcs12.c +257 -0
  35. data/ext/openssl/ossl_pkcs12.h +13 -0
  36. data/ext/openssl/ossl_pkcs7.c +1098 -0
  37. data/ext/openssl/ossl_pkcs7.h +36 -0
  38. data/ext/openssl/ossl_pkey.c +673 -0
  39. data/ext/openssl/ossl_pkey.h +241 -0
  40. data/ext/openssl/ossl_pkey_dh.c +650 -0
  41. data/ext/openssl/ossl_pkey_dsa.c +664 -0
  42. data/ext/openssl/ossl_pkey_ec.c +1827 -0
  43. data/ext/openssl/ossl_pkey_rsa.c +966 -0
  44. data/ext/openssl/ossl_rand.c +200 -0
  45. data/ext/openssl/ossl_rand.h +18 -0
  46. data/ext/openssl/ossl_ssl.c +3080 -0
  47. data/ext/openssl/ossl_ssl.h +36 -0
  48. data/ext/openssl/ossl_ssl_session.c +332 -0
  49. data/ext/openssl/ossl_ts.c +1524 -0
  50. data/ext/openssl/ossl_ts.h +16 -0
  51. data/ext/openssl/ossl_x509.c +262 -0
  52. data/ext/openssl/ossl_x509.h +115 -0
  53. data/ext/openssl/ossl_x509attr.c +324 -0
  54. data/ext/openssl/ossl_x509cert.c +846 -0
  55. data/ext/openssl/ossl_x509crl.c +542 -0
  56. data/ext/openssl/ossl_x509ext.c +491 -0
  57. data/ext/openssl/ossl_x509name.c +590 -0
  58. data/ext/openssl/ossl_x509req.c +441 -0
  59. data/ext/openssl/ossl_x509revoked.c +300 -0
  60. data/ext/openssl/ossl_x509store.c +902 -0
  61. data/ext/openssl/ruby_missing.h +24 -0
  62. data/lib/openssl/bn.rb +40 -0
  63. data/lib/openssl/buffering.rb +478 -0
  64. data/lib/openssl/cipher.rb +67 -0
  65. data/lib/openssl/config.rb +501 -0
  66. data/lib/openssl/digest.rb +73 -0
  67. data/lib/openssl/hmac.rb +13 -0
  68. data/lib/openssl/marshal.rb +30 -0
  69. data/lib/openssl/pkcs5.rb +22 -0
  70. data/lib/openssl/pkey.rb +42 -0
  71. data/lib/openssl/ssl.rb +542 -0
  72. data/lib/openssl/version.rb +5 -0
  73. data/lib/openssl/x509.rb +369 -0
  74. data/lib/openssl.rb +38 -0
  75. metadata +196 -0
@@ -0,0 +1,441 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ #define NewX509Req(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_x509req_type, 0)
14
+ #define SetX509Req(obj, req) do { \
15
+ if (!(req)) { \
16
+ ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
17
+ } \
18
+ RTYPEDDATA_DATA(obj) = (req); \
19
+ } while (0)
20
+ #define GetX509Req(obj, req) do { \
21
+ TypedData_Get_Struct((obj), X509_REQ, &ossl_x509req_type, (req)); \
22
+ if (!(req)) { \
23
+ ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
24
+ } \
25
+ } while (0)
26
+
27
+ /*
28
+ * Classes
29
+ */
30
+ VALUE cX509Req;
31
+ VALUE eX509ReqError;
32
+
33
+ static void
34
+ ossl_x509req_free(void *ptr)
35
+ {
36
+ X509_REQ_free(ptr);
37
+ }
38
+
39
+ static const rb_data_type_t ossl_x509req_type = {
40
+ "OpenSSL/X509/REQ",
41
+ {
42
+ 0, ossl_x509req_free,
43
+ },
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
45
+ };
46
+
47
+ /*
48
+ * Public functions
49
+ */
50
+ X509_REQ *
51
+ GetX509ReqPtr(VALUE obj)
52
+ {
53
+ X509_REQ *req;
54
+
55
+ GetX509Req(obj, req);
56
+
57
+ return req;
58
+ }
59
+
60
+ /*
61
+ * Private functions
62
+ */
63
+ static VALUE
64
+ ossl_x509req_alloc(VALUE klass)
65
+ {
66
+ X509_REQ *req;
67
+ VALUE obj;
68
+
69
+ obj = NewX509Req(klass);
70
+ if (!(req = X509_REQ_new())) {
71
+ ossl_raise(eX509ReqError, NULL);
72
+ }
73
+ SetX509Req(obj, req);
74
+
75
+ return obj;
76
+ }
77
+
78
+ static VALUE
79
+ ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
80
+ {
81
+ BIO *in;
82
+ X509_REQ *req, *x = DATA_PTR(self);
83
+ VALUE arg;
84
+
85
+ if (rb_scan_args(argc, argv, "01", &arg) == 0) {
86
+ return self;
87
+ }
88
+ arg = ossl_to_der_if_possible(arg);
89
+ in = ossl_obj2bio(&arg);
90
+ req = PEM_read_bio_X509_REQ(in, &x, NULL, NULL);
91
+ DATA_PTR(self) = x;
92
+ if (!req) {
93
+ OSSL_BIO_reset(in);
94
+ req = d2i_X509_REQ_bio(in, &x);
95
+ DATA_PTR(self) = x;
96
+ }
97
+ BIO_free(in);
98
+ if (!req) ossl_raise(eX509ReqError, NULL);
99
+
100
+ return self;
101
+ }
102
+
103
+ static VALUE
104
+ ossl_x509req_copy(VALUE self, VALUE other)
105
+ {
106
+ X509_REQ *a, *b, *req;
107
+
108
+ rb_check_frozen(self);
109
+ if (self == other) return self;
110
+ GetX509Req(self, a);
111
+ GetX509Req(other, b);
112
+ if (!(req = X509_REQ_dup(b))) {
113
+ ossl_raise(eX509ReqError, NULL);
114
+ }
115
+ X509_REQ_free(a);
116
+ DATA_PTR(self) = req;
117
+
118
+ return self;
119
+ }
120
+
121
+ static VALUE
122
+ ossl_x509req_to_pem(VALUE self)
123
+ {
124
+ X509_REQ *req;
125
+ BIO *out;
126
+
127
+ GetX509Req(self, req);
128
+ if (!(out = BIO_new(BIO_s_mem()))) {
129
+ ossl_raise(eX509ReqError, NULL);
130
+ }
131
+ if (!PEM_write_bio_X509_REQ(out, req)) {
132
+ BIO_free(out);
133
+ ossl_raise(eX509ReqError, NULL);
134
+ }
135
+
136
+ return ossl_membio2str(out);
137
+ }
138
+
139
+ static VALUE
140
+ ossl_x509req_to_der(VALUE self)
141
+ {
142
+ X509_REQ *req;
143
+ VALUE str;
144
+ long len;
145
+ unsigned char *p;
146
+
147
+ GetX509Req(self, req);
148
+ if ((len = i2d_X509_REQ(req, NULL)) <= 0)
149
+ ossl_raise(eX509ReqError, NULL);
150
+ str = rb_str_new(0, len);
151
+ p = (unsigned char *)RSTRING_PTR(str);
152
+ if (i2d_X509_REQ(req, &p) <= 0)
153
+ ossl_raise(eX509ReqError, NULL);
154
+ ossl_str_adjust(str, p);
155
+
156
+ return str;
157
+ }
158
+
159
+ static VALUE
160
+ ossl_x509req_to_text(VALUE self)
161
+ {
162
+ X509_REQ *req;
163
+ BIO *out;
164
+
165
+ GetX509Req(self, req);
166
+ if (!(out = BIO_new(BIO_s_mem()))) {
167
+ ossl_raise(eX509ReqError, NULL);
168
+ }
169
+ if (!X509_REQ_print(out, req)) {
170
+ BIO_free(out);
171
+ ossl_raise(eX509ReqError, NULL);
172
+ }
173
+
174
+ return ossl_membio2str(out);
175
+ }
176
+
177
+ #if 0
178
+ /*
179
+ * Makes X509 from X509_REQuest
180
+ */
181
+ static VALUE
182
+ ossl_x509req_to_x509(VALUE self, VALUE days, VALUE key)
183
+ {
184
+ X509_REQ *req;
185
+ X509 *x509;
186
+
187
+ GetX509Req(self, req);
188
+ ...
189
+ if (!(x509 = X509_REQ_to_X509(req, d, pkey))) {
190
+ ossl_raise(eX509ReqError, NULL);
191
+ }
192
+
193
+ return ossl_x509_new(x509);
194
+ }
195
+ #endif
196
+
197
+ static VALUE
198
+ ossl_x509req_get_version(VALUE self)
199
+ {
200
+ X509_REQ *req;
201
+ long version;
202
+
203
+ GetX509Req(self, req);
204
+ version = X509_REQ_get_version(req);
205
+
206
+ return LONG2NUM(version);
207
+ }
208
+
209
+ static VALUE
210
+ ossl_x509req_set_version(VALUE self, VALUE version)
211
+ {
212
+ X509_REQ *req;
213
+ long ver;
214
+
215
+ if ((ver = NUM2LONG(version)) < 0) {
216
+ ossl_raise(eX509ReqError, "version must be >= 0!");
217
+ }
218
+ GetX509Req(self, req);
219
+ if (!X509_REQ_set_version(req, ver)) {
220
+ ossl_raise(eX509ReqError, "X509_REQ_set_version");
221
+ }
222
+
223
+ return version;
224
+ }
225
+
226
+ static VALUE
227
+ ossl_x509req_get_subject(VALUE self)
228
+ {
229
+ X509_REQ *req;
230
+ X509_NAME *name;
231
+
232
+ GetX509Req(self, req);
233
+ if (!(name = X509_REQ_get_subject_name(req))) { /* NO DUP - don't free */
234
+ ossl_raise(eX509ReqError, NULL);
235
+ }
236
+
237
+ return ossl_x509name_new(name);
238
+ }
239
+
240
+ static VALUE
241
+ ossl_x509req_set_subject(VALUE self, VALUE subject)
242
+ {
243
+ X509_REQ *req;
244
+
245
+ GetX509Req(self, req);
246
+ /* DUPs name */
247
+ if (!X509_REQ_set_subject_name(req, GetX509NamePtr(subject))) {
248
+ ossl_raise(eX509ReqError, NULL);
249
+ }
250
+
251
+ return subject;
252
+ }
253
+
254
+ static VALUE
255
+ ossl_x509req_get_signature_algorithm(VALUE self)
256
+ {
257
+ X509_REQ *req;
258
+ const X509_ALGOR *alg;
259
+ BIO *out;
260
+
261
+ GetX509Req(self, req);
262
+
263
+ if (!(out = BIO_new(BIO_s_mem()))) {
264
+ ossl_raise(eX509ReqError, NULL);
265
+ }
266
+ X509_REQ_get0_signature(req, NULL, &alg);
267
+ if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
268
+ BIO_free(out);
269
+ ossl_raise(eX509ReqError, NULL);
270
+ }
271
+
272
+ return ossl_membio2str(out);
273
+ }
274
+
275
+ static VALUE
276
+ ossl_x509req_get_public_key(VALUE self)
277
+ {
278
+ X509_REQ *req;
279
+ EVP_PKEY *pkey;
280
+
281
+ GetX509Req(self, req);
282
+ if (!(pkey = X509_REQ_get_pubkey(req))) { /* adds reference */
283
+ ossl_raise(eX509ReqError, NULL);
284
+ }
285
+
286
+ return ossl_pkey_new(pkey); /* NO DUP - OK */
287
+ }
288
+
289
+ static VALUE
290
+ ossl_x509req_set_public_key(VALUE self, VALUE key)
291
+ {
292
+ X509_REQ *req;
293
+ EVP_PKEY *pkey;
294
+
295
+ GetX509Req(self, req);
296
+ pkey = GetPKeyPtr(key);
297
+ ossl_pkey_check_public_key(pkey);
298
+ if (!X509_REQ_set_pubkey(req, pkey))
299
+ ossl_raise(eX509ReqError, "X509_REQ_set_pubkey");
300
+ return key;
301
+ }
302
+
303
+ static VALUE
304
+ ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
305
+ {
306
+ X509_REQ *req;
307
+ EVP_PKEY *pkey;
308
+ const EVP_MD *md;
309
+
310
+ GetX509Req(self, req);
311
+ pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
312
+ md = ossl_evp_get_digestbyname(digest);
313
+ if (!X509_REQ_sign(req, pkey, md)) {
314
+ ossl_raise(eX509ReqError, NULL);
315
+ }
316
+
317
+ return self;
318
+ }
319
+
320
+ /*
321
+ * Checks that cert signature is made with PRIVversion of this PUBLIC 'key'
322
+ */
323
+ static VALUE
324
+ ossl_x509req_verify(VALUE self, VALUE key)
325
+ {
326
+ X509_REQ *req;
327
+ EVP_PKEY *pkey;
328
+
329
+ GetX509Req(self, req);
330
+ pkey = GetPKeyPtr(key);
331
+ ossl_pkey_check_public_key(pkey);
332
+ switch (X509_REQ_verify(req, pkey)) {
333
+ case 1:
334
+ return Qtrue;
335
+ case 0:
336
+ ossl_clear_error();
337
+ return Qfalse;
338
+ default:
339
+ ossl_raise(eX509ReqError, NULL);
340
+ }
341
+ }
342
+
343
+ static VALUE
344
+ ossl_x509req_get_attributes(VALUE self)
345
+ {
346
+ X509_REQ *req;
347
+ int count, i;
348
+ X509_ATTRIBUTE *attr;
349
+ VALUE ary;
350
+
351
+ GetX509Req(self, req);
352
+
353
+ count = X509_REQ_get_attr_count(req);
354
+ if (count < 0) {
355
+ OSSL_Debug("count < 0???");
356
+ return rb_ary_new();
357
+ }
358
+ ary = rb_ary_new2(count);
359
+ for (i=0; i<count; i++) {
360
+ attr = X509_REQ_get_attr(req, i);
361
+ rb_ary_push(ary, ossl_x509attr_new(attr));
362
+ }
363
+
364
+ return ary;
365
+ }
366
+
367
+ static VALUE
368
+ ossl_x509req_set_attributes(VALUE self, VALUE ary)
369
+ {
370
+ X509_REQ *req;
371
+ X509_ATTRIBUTE *attr;
372
+ long i;
373
+ VALUE item;
374
+
375
+ Check_Type(ary, T_ARRAY);
376
+ for (i=0;i<RARRAY_LEN(ary); i++) {
377
+ OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Attr);
378
+ }
379
+ GetX509Req(self, req);
380
+ while ((attr = X509_REQ_delete_attr(req, 0)))
381
+ X509_ATTRIBUTE_free(attr);
382
+ for (i=0;i<RARRAY_LEN(ary); i++) {
383
+ item = RARRAY_AREF(ary, i);
384
+ attr = GetX509AttrPtr(item);
385
+ if (!X509_REQ_add1_attr(req, attr)) {
386
+ ossl_raise(eX509ReqError, NULL);
387
+ }
388
+ }
389
+ return ary;
390
+ }
391
+
392
+ static VALUE
393
+ ossl_x509req_add_attribute(VALUE self, VALUE attr)
394
+ {
395
+ X509_REQ *req;
396
+
397
+ GetX509Req(self, req);
398
+ if (!X509_REQ_add1_attr(req, GetX509AttrPtr(attr))) {
399
+ ossl_raise(eX509ReqError, NULL);
400
+ }
401
+
402
+ return attr;
403
+ }
404
+
405
+ /*
406
+ * X509_REQUEST init
407
+ */
408
+ void
409
+ Init_ossl_x509req(void)
410
+ {
411
+ #if 0
412
+ mOSSL = rb_define_module("OpenSSL");
413
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
414
+ mX509 = rb_define_module_under(mOSSL, "X509");
415
+ #endif
416
+
417
+ eX509ReqError = rb_define_class_under(mX509, "RequestError", eOSSLError);
418
+
419
+ cX509Req = rb_define_class_under(mX509, "Request", rb_cObject);
420
+
421
+ rb_define_alloc_func(cX509Req, ossl_x509req_alloc);
422
+ rb_define_method(cX509Req, "initialize", ossl_x509req_initialize, -1);
423
+ rb_define_method(cX509Req, "initialize_copy", ossl_x509req_copy, 1);
424
+
425
+ rb_define_method(cX509Req, "to_pem", ossl_x509req_to_pem, 0);
426
+ rb_define_method(cX509Req, "to_der", ossl_x509req_to_der, 0);
427
+ rb_define_alias(cX509Req, "to_s", "to_pem");
428
+ rb_define_method(cX509Req, "to_text", ossl_x509req_to_text, 0);
429
+ rb_define_method(cX509Req, "version", ossl_x509req_get_version, 0);
430
+ rb_define_method(cX509Req, "version=", ossl_x509req_set_version, 1);
431
+ rb_define_method(cX509Req, "subject", ossl_x509req_get_subject, 0);
432
+ rb_define_method(cX509Req, "subject=", ossl_x509req_set_subject, 1);
433
+ rb_define_method(cX509Req, "signature_algorithm", ossl_x509req_get_signature_algorithm, 0);
434
+ rb_define_method(cX509Req, "public_key", ossl_x509req_get_public_key, 0);
435
+ rb_define_method(cX509Req, "public_key=", ossl_x509req_set_public_key, 1);
436
+ rb_define_method(cX509Req, "sign", ossl_x509req_sign, 2);
437
+ rb_define_method(cX509Req, "verify", ossl_x509req_verify, 1);
438
+ rb_define_method(cX509Req, "attributes", ossl_x509req_get_attributes, 0);
439
+ rb_define_method(cX509Req, "attributes=", ossl_x509req_set_attributes, 1);
440
+ rb_define_method(cX509Req, "add_attribute", ossl_x509req_add_attribute, 1);
441
+ }
@@ -0,0 +1,300 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ #define NewX509Rev(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_x509rev_type, 0)
14
+ #define SetX509Rev(obj, rev) do { \
15
+ if (!(rev)) { \
16
+ ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
17
+ } \
18
+ RTYPEDDATA_DATA(obj) = (rev); \
19
+ } while (0)
20
+ #define GetX509Rev(obj, rev) do { \
21
+ TypedData_Get_Struct((obj), X509_REVOKED, &ossl_x509rev_type, (rev)); \
22
+ if (!(rev)) { \
23
+ ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
24
+ } \
25
+ } while (0)
26
+
27
+ /*
28
+ * Classes
29
+ */
30
+ VALUE cX509Rev;
31
+ VALUE eX509RevError;
32
+
33
+ static void
34
+ ossl_x509rev_free(void *ptr)
35
+ {
36
+ X509_REVOKED_free(ptr);
37
+ }
38
+
39
+ static const rb_data_type_t ossl_x509rev_type = {
40
+ "OpenSSL/X509/REV",
41
+ {
42
+ 0, ossl_x509rev_free,
43
+ },
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
45
+ };
46
+
47
+ /*
48
+ * PUBLIC
49
+ */
50
+ VALUE
51
+ ossl_x509revoked_new(X509_REVOKED *rev)
52
+ {
53
+ X509_REVOKED *new;
54
+ VALUE obj;
55
+
56
+ obj = NewX509Rev(cX509Rev);
57
+ if (!rev) {
58
+ new = X509_REVOKED_new();
59
+ } else {
60
+ new = X509_REVOKED_dup(rev);
61
+ }
62
+ if (!new) {
63
+ ossl_raise(eX509RevError, NULL);
64
+ }
65
+ SetX509Rev(obj, new);
66
+
67
+ return obj;
68
+ }
69
+
70
+ X509_REVOKED *
71
+ DupX509RevokedPtr(VALUE obj)
72
+ {
73
+ X509_REVOKED *rev, *new;
74
+
75
+ GetX509Rev(obj, rev);
76
+ if (!(new = X509_REVOKED_dup(rev))) {
77
+ ossl_raise(eX509RevError, NULL);
78
+ }
79
+
80
+ return new;
81
+ }
82
+
83
+ /*
84
+ * PRIVATE
85
+ */
86
+ static VALUE
87
+ ossl_x509revoked_alloc(VALUE klass)
88
+ {
89
+ X509_REVOKED *rev;
90
+ VALUE obj;
91
+
92
+ obj = NewX509Rev(klass);
93
+ if (!(rev = X509_REVOKED_new())) {
94
+ ossl_raise(eX509RevError, NULL);
95
+ }
96
+ SetX509Rev(obj, rev);
97
+
98
+ return obj;
99
+ }
100
+
101
+ static VALUE
102
+ ossl_x509revoked_initialize(int argc, VALUE *argv, VALUE self)
103
+ {
104
+ /* EMPTY */
105
+ return self;
106
+ }
107
+
108
+ static VALUE
109
+ ossl_x509revoked_initialize_copy(VALUE self, VALUE other)
110
+ {
111
+ X509_REVOKED *rev, *rev_other, *rev_new;
112
+
113
+ rb_check_frozen(self);
114
+ GetX509Rev(self, rev);
115
+ GetX509Rev(other, rev_other);
116
+
117
+ rev_new = X509_REVOKED_dup(rev_other);
118
+ if (!rev_new)
119
+ ossl_raise(eX509RevError, "X509_REVOKED_dup");
120
+
121
+ SetX509Rev(self, rev_new);
122
+ X509_REVOKED_free(rev);
123
+
124
+ return self;
125
+ }
126
+
127
+ static VALUE
128
+ ossl_x509revoked_get_serial(VALUE self)
129
+ {
130
+ X509_REVOKED *rev;
131
+
132
+ GetX509Rev(self, rev);
133
+
134
+ return asn1integer_to_num(X509_REVOKED_get0_serialNumber(rev));
135
+ }
136
+
137
+ static VALUE
138
+ ossl_x509revoked_set_serial(VALUE self, VALUE num)
139
+ {
140
+ X509_REVOKED *rev;
141
+ ASN1_INTEGER *asn1int;
142
+
143
+ GetX509Rev(self, rev);
144
+ asn1int = num_to_asn1integer(num, NULL);
145
+ if (!X509_REVOKED_set_serialNumber(rev, asn1int)) {
146
+ ASN1_INTEGER_free(asn1int);
147
+ ossl_raise(eX509RevError, "X509_REVOKED_set_serialNumber");
148
+ }
149
+ ASN1_INTEGER_free(asn1int);
150
+
151
+ return num;
152
+ }
153
+
154
+ static VALUE
155
+ ossl_x509revoked_get_time(VALUE self)
156
+ {
157
+ X509_REVOKED *rev;
158
+ const ASN1_TIME *time;
159
+
160
+ GetX509Rev(self, rev);
161
+ time = X509_REVOKED_get0_revocationDate(rev);
162
+ if (!time)
163
+ return Qnil;
164
+
165
+ return asn1time_to_time(time);
166
+ }
167
+
168
+ static VALUE
169
+ ossl_x509revoked_set_time(VALUE self, VALUE time)
170
+ {
171
+ X509_REVOKED *rev;
172
+ ASN1_TIME *asn1time;
173
+
174
+ GetX509Rev(self, rev);
175
+ asn1time = ossl_x509_time_adjust(NULL, time);
176
+ if (!X509_REVOKED_set_revocationDate(rev, asn1time)) {
177
+ ASN1_TIME_free(asn1time);
178
+ ossl_raise(eX509RevError, "X509_REVOKED_set_revocationDate");
179
+ }
180
+ ASN1_TIME_free(asn1time);
181
+
182
+ return time;
183
+ }
184
+ /*
185
+ * Gets X509v3 extensions as array of X509Ext objects
186
+ */
187
+ static VALUE
188
+ ossl_x509revoked_get_extensions(VALUE self)
189
+ {
190
+ X509_REVOKED *rev;
191
+ int count, i;
192
+ X509_EXTENSION *ext;
193
+ VALUE ary;
194
+
195
+ GetX509Rev(self, rev);
196
+ count = X509_REVOKED_get_ext_count(rev);
197
+ if (count < 0) {
198
+ OSSL_Debug("count < 0???");
199
+ return rb_ary_new();
200
+ }
201
+ ary = rb_ary_new2(count);
202
+ for (i=0; i<count; i++) {
203
+ ext = X509_REVOKED_get_ext(rev, i);
204
+ rb_ary_push(ary, ossl_x509ext_new(ext));
205
+ }
206
+
207
+ return ary;
208
+ }
209
+
210
+ /*
211
+ * Sets X509_EXTENSIONs
212
+ */
213
+ static VALUE
214
+ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
215
+ {
216
+ X509_REVOKED *rev;
217
+ X509_EXTENSION *ext;
218
+ long i;
219
+ VALUE item;
220
+
221
+ Check_Type(ary, T_ARRAY);
222
+ for (i=0; i<RARRAY_LEN(ary); i++) {
223
+ OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
224
+ }
225
+ GetX509Rev(self, rev);
226
+ while ((ext = X509_REVOKED_delete_ext(rev, 0)))
227
+ X509_EXTENSION_free(ext);
228
+ for (i=0; i<RARRAY_LEN(ary); i++) {
229
+ item = RARRAY_AREF(ary, i);
230
+ ext = GetX509ExtPtr(item);
231
+ if(!X509_REVOKED_add_ext(rev, ext, -1)) {
232
+ ossl_raise(eX509RevError, NULL);
233
+ }
234
+ }
235
+
236
+ return ary;
237
+ }
238
+
239
+ static VALUE
240
+ ossl_x509revoked_add_extension(VALUE self, VALUE ext)
241
+ {
242
+ X509_REVOKED *rev;
243
+
244
+ GetX509Rev(self, rev);
245
+ if (!X509_REVOKED_add_ext(rev, GetX509ExtPtr(ext), -1)) {
246
+ ossl_raise(eX509RevError, NULL);
247
+ }
248
+
249
+ return ext;
250
+ }
251
+
252
+ static VALUE
253
+ ossl_x509revoked_to_der(VALUE self)
254
+ {
255
+ X509_REVOKED *rev;
256
+ VALUE str;
257
+ int len;
258
+ unsigned char *p;
259
+
260
+ GetX509Rev(self, rev);
261
+ len = i2d_X509_REVOKED(rev, NULL);
262
+ if (len <= 0)
263
+ ossl_raise(eX509RevError, "i2d_X509_REVOKED");
264
+ str = rb_str_new(NULL, len);
265
+ p = (unsigned char *)RSTRING_PTR(str);
266
+ if (i2d_X509_REVOKED(rev, &p) <= 0)
267
+ ossl_raise(eX509RevError, "i2d_X509_REVOKED");
268
+ ossl_str_adjust(str, p);
269
+ return str;
270
+ }
271
+
272
+ /*
273
+ * INIT
274
+ */
275
+ void
276
+ Init_ossl_x509revoked(void)
277
+ {
278
+ #if 0
279
+ mOSSL = rb_define_module("OpenSSL");
280
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
281
+ mX509 = rb_define_module_under(mOSSL, "X509");
282
+ #endif
283
+
284
+ eX509RevError = rb_define_class_under(mX509, "RevokedError", eOSSLError);
285
+
286
+ cX509Rev = rb_define_class_under(mX509, "Revoked", rb_cObject);
287
+
288
+ rb_define_alloc_func(cX509Rev, ossl_x509revoked_alloc);
289
+ rb_define_method(cX509Rev, "initialize", ossl_x509revoked_initialize, -1);
290
+ rb_define_method(cX509Rev, "initialize_copy", ossl_x509revoked_initialize_copy, 1);
291
+
292
+ rb_define_method(cX509Rev, "serial", ossl_x509revoked_get_serial, 0);
293
+ rb_define_method(cX509Rev, "serial=", ossl_x509revoked_set_serial, 1);
294
+ rb_define_method(cX509Rev, "time", ossl_x509revoked_get_time, 0);
295
+ rb_define_method(cX509Rev, "time=", ossl_x509revoked_set_time, 1);
296
+ rb_define_method(cX509Rev, "extensions", ossl_x509revoked_get_extensions, 0);
297
+ rb_define_method(cX509Rev, "extensions=", ossl_x509revoked_set_extensions, 1);
298
+ rb_define_method(cX509Rev, "add_extension", ossl_x509revoked_add_extension, 1);
299
+ rb_define_method(cX509Rev, "to_der", ossl_x509revoked_to_der, 0);
300
+ }