openssl 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of openssl might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/BSDL +22 -0
- data/CONTRIBUTING.md +130 -0
- data/History.md +118 -0
- data/LICENSE.txt +56 -0
- data/README.md +70 -0
- data/ext/openssl/deprecation.rb +26 -0
- data/ext/openssl/extconf.rb +158 -0
- data/ext/openssl/openssl_missing.c +173 -0
- data/ext/openssl/openssl_missing.h +244 -0
- data/ext/openssl/ossl.c +1201 -0
- data/ext/openssl/ossl.h +222 -0
- data/ext/openssl/ossl_asn1.c +1992 -0
- data/ext/openssl/ossl_asn1.h +66 -0
- data/ext/openssl/ossl_bio.c +87 -0
- data/ext/openssl/ossl_bio.h +19 -0
- data/ext/openssl/ossl_bn.c +1153 -0
- data/ext/openssl/ossl_bn.h +23 -0
- data/ext/openssl/ossl_cipher.c +1085 -0
- data/ext/openssl/ossl_cipher.h +20 -0
- data/ext/openssl/ossl_config.c +89 -0
- data/ext/openssl/ossl_config.h +19 -0
- data/ext/openssl/ossl_digest.c +453 -0
- data/ext/openssl/ossl_digest.h +20 -0
- data/ext/openssl/ossl_engine.c +580 -0
- data/ext/openssl/ossl_engine.h +19 -0
- data/ext/openssl/ossl_hmac.c +398 -0
- data/ext/openssl/ossl_hmac.h +18 -0
- data/ext/openssl/ossl_ns_spki.c +406 -0
- data/ext/openssl/ossl_ns_spki.h +19 -0
- data/ext/openssl/ossl_ocsp.c +2013 -0
- data/ext/openssl/ossl_ocsp.h +23 -0
- data/ext/openssl/ossl_pkcs12.c +259 -0
- data/ext/openssl/ossl_pkcs12.h +13 -0
- data/ext/openssl/ossl_pkcs5.c +180 -0
- data/ext/openssl/ossl_pkcs5.h +6 -0
- data/ext/openssl/ossl_pkcs7.c +1125 -0
- data/ext/openssl/ossl_pkcs7.h +20 -0
- data/ext/openssl/ossl_pkey.c +435 -0
- data/ext/openssl/ossl_pkey.h +245 -0
- data/ext/openssl/ossl_pkey_dh.c +650 -0
- data/ext/openssl/ossl_pkey_dsa.c +672 -0
- data/ext/openssl/ossl_pkey_ec.c +1899 -0
- data/ext/openssl/ossl_pkey_rsa.c +768 -0
- data/ext/openssl/ossl_rand.c +238 -0
- data/ext/openssl/ossl_rand.h +18 -0
- data/ext/openssl/ossl_ssl.c +2679 -0
- data/ext/openssl/ossl_ssl.h +41 -0
- data/ext/openssl/ossl_ssl_session.c +352 -0
- data/ext/openssl/ossl_version.h +15 -0
- data/ext/openssl/ossl_x509.c +186 -0
- data/ext/openssl/ossl_x509.h +119 -0
- data/ext/openssl/ossl_x509attr.c +328 -0
- data/ext/openssl/ossl_x509cert.c +860 -0
- data/ext/openssl/ossl_x509crl.c +565 -0
- data/ext/openssl/ossl_x509ext.c +480 -0
- data/ext/openssl/ossl_x509name.c +547 -0
- data/ext/openssl/ossl_x509req.c +492 -0
- data/ext/openssl/ossl_x509revoked.c +279 -0
- data/ext/openssl/ossl_x509store.c +846 -0
- data/ext/openssl/ruby_missing.h +32 -0
- data/lib/openssl.rb +21 -0
- data/lib/openssl/bn.rb +39 -0
- data/lib/openssl/buffering.rb +451 -0
- data/lib/openssl/cipher.rb +67 -0
- data/lib/openssl/config.rb +473 -0
- data/lib/openssl/digest.rb +78 -0
- data/lib/openssl/pkey.rb +44 -0
- data/lib/openssl/ssl.rb +416 -0
- data/lib/openssl/x509.rb +176 -0
- metadata +178 -0
@@ -0,0 +1,565 @@
|
|
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 NewX509CRL(klass) \
|
13
|
+
TypedData_Wrap_Struct((klass), &ossl_x509crl_type, 0)
|
14
|
+
#define SetX509CRL(obj, crl) do { \
|
15
|
+
if (!(crl)) { \
|
16
|
+
ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
|
17
|
+
} \
|
18
|
+
RTYPEDDATA_DATA(obj) = (crl); \
|
19
|
+
} while (0)
|
20
|
+
#define GetX509CRL(obj, crl) do { \
|
21
|
+
TypedData_Get_Struct((obj), X509_CRL, &ossl_x509crl_type, (crl)); \
|
22
|
+
if (!(crl)) { \
|
23
|
+
ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
|
24
|
+
} \
|
25
|
+
} while (0)
|
26
|
+
#define SafeGetX509CRL(obj, crl) do { \
|
27
|
+
OSSL_Check_Kind((obj), cX509CRL); \
|
28
|
+
GetX509CRL((obj), (crl)); \
|
29
|
+
} while (0)
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Classes
|
33
|
+
*/
|
34
|
+
VALUE cX509CRL;
|
35
|
+
VALUE eX509CRLError;
|
36
|
+
|
37
|
+
static void
|
38
|
+
ossl_x509crl_free(void *ptr)
|
39
|
+
{
|
40
|
+
X509_CRL_free(ptr);
|
41
|
+
}
|
42
|
+
|
43
|
+
static const rb_data_type_t ossl_x509crl_type = {
|
44
|
+
"OpenSSL/X509/CRL",
|
45
|
+
{
|
46
|
+
0, ossl_x509crl_free,
|
47
|
+
},
|
48
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
49
|
+
};
|
50
|
+
|
51
|
+
/*
|
52
|
+
* PUBLIC
|
53
|
+
*/
|
54
|
+
X509_CRL *
|
55
|
+
GetX509CRLPtr(VALUE obj)
|
56
|
+
{
|
57
|
+
X509_CRL *crl;
|
58
|
+
|
59
|
+
SafeGetX509CRL(obj, crl);
|
60
|
+
|
61
|
+
return crl;
|
62
|
+
}
|
63
|
+
|
64
|
+
X509_CRL *
|
65
|
+
DupX509CRLPtr(VALUE obj)
|
66
|
+
{
|
67
|
+
X509_CRL *crl;
|
68
|
+
|
69
|
+
SafeGetX509CRL(obj, crl);
|
70
|
+
X509_CRL_up_ref(crl);
|
71
|
+
|
72
|
+
return crl;
|
73
|
+
}
|
74
|
+
|
75
|
+
VALUE
|
76
|
+
ossl_x509crl_new(X509_CRL *crl)
|
77
|
+
{
|
78
|
+
X509_CRL *tmp;
|
79
|
+
VALUE obj;
|
80
|
+
|
81
|
+
obj = NewX509CRL(cX509CRL);
|
82
|
+
tmp = crl ? X509_CRL_dup(crl) : X509_CRL_new();
|
83
|
+
if(!tmp) ossl_raise(eX509CRLError, NULL);
|
84
|
+
SetX509CRL(obj, tmp);
|
85
|
+
|
86
|
+
return obj;
|
87
|
+
}
|
88
|
+
|
89
|
+
/*
|
90
|
+
* PRIVATE
|
91
|
+
*/
|
92
|
+
static VALUE
|
93
|
+
ossl_x509crl_alloc(VALUE klass)
|
94
|
+
{
|
95
|
+
X509_CRL *crl;
|
96
|
+
VALUE obj;
|
97
|
+
|
98
|
+
obj = NewX509CRL(klass);
|
99
|
+
if (!(crl = X509_CRL_new())) {
|
100
|
+
ossl_raise(eX509CRLError, NULL);
|
101
|
+
}
|
102
|
+
SetX509CRL(obj, crl);
|
103
|
+
|
104
|
+
return obj;
|
105
|
+
}
|
106
|
+
|
107
|
+
static VALUE
|
108
|
+
ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
|
109
|
+
{
|
110
|
+
BIO *in;
|
111
|
+
X509_CRL *crl, *x = DATA_PTR(self);
|
112
|
+
VALUE arg;
|
113
|
+
|
114
|
+
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
arg = ossl_to_der_if_possible(arg);
|
118
|
+
in = ossl_obj2bio(arg);
|
119
|
+
crl = PEM_read_bio_X509_CRL(in, &x, NULL, NULL);
|
120
|
+
DATA_PTR(self) = x;
|
121
|
+
if (!crl) {
|
122
|
+
OSSL_BIO_reset(in);
|
123
|
+
crl = d2i_X509_CRL_bio(in, &x);
|
124
|
+
DATA_PTR(self) = x;
|
125
|
+
}
|
126
|
+
BIO_free(in);
|
127
|
+
if (!crl) ossl_raise(eX509CRLError, NULL);
|
128
|
+
|
129
|
+
return self;
|
130
|
+
}
|
131
|
+
|
132
|
+
static VALUE
|
133
|
+
ossl_x509crl_copy(VALUE self, VALUE other)
|
134
|
+
{
|
135
|
+
X509_CRL *a, *b, *crl;
|
136
|
+
|
137
|
+
rb_check_frozen(self);
|
138
|
+
if (self == other) return self;
|
139
|
+
GetX509CRL(self, a);
|
140
|
+
SafeGetX509CRL(other, b);
|
141
|
+
if (!(crl = X509_CRL_dup(b))) {
|
142
|
+
ossl_raise(eX509CRLError, NULL);
|
143
|
+
}
|
144
|
+
X509_CRL_free(a);
|
145
|
+
DATA_PTR(self) = crl;
|
146
|
+
|
147
|
+
return self;
|
148
|
+
}
|
149
|
+
|
150
|
+
static VALUE
|
151
|
+
ossl_x509crl_get_version(VALUE self)
|
152
|
+
{
|
153
|
+
X509_CRL *crl;
|
154
|
+
long ver;
|
155
|
+
|
156
|
+
GetX509CRL(self, crl);
|
157
|
+
ver = X509_CRL_get_version(crl);
|
158
|
+
|
159
|
+
return LONG2NUM(ver);
|
160
|
+
}
|
161
|
+
|
162
|
+
static VALUE
|
163
|
+
ossl_x509crl_set_version(VALUE self, VALUE version)
|
164
|
+
{
|
165
|
+
X509_CRL *crl;
|
166
|
+
long ver;
|
167
|
+
|
168
|
+
if ((ver = NUM2LONG(version)) < 0) {
|
169
|
+
ossl_raise(eX509CRLError, "version must be >= 0!");
|
170
|
+
}
|
171
|
+
GetX509CRL(self, crl);
|
172
|
+
if (!X509_CRL_set_version(crl, ver)) {
|
173
|
+
ossl_raise(eX509CRLError, NULL);
|
174
|
+
}
|
175
|
+
|
176
|
+
return version;
|
177
|
+
}
|
178
|
+
|
179
|
+
static VALUE
|
180
|
+
ossl_x509crl_get_signature_algorithm(VALUE self)
|
181
|
+
{
|
182
|
+
X509_CRL *crl;
|
183
|
+
const X509_ALGOR *alg;
|
184
|
+
BIO *out;
|
185
|
+
BUF_MEM *buf;
|
186
|
+
VALUE str;
|
187
|
+
|
188
|
+
GetX509CRL(self, crl);
|
189
|
+
if (!(out = BIO_new(BIO_s_mem()))) {
|
190
|
+
ossl_raise(eX509CRLError, NULL);
|
191
|
+
}
|
192
|
+
X509_CRL_get0_signature(crl, NULL, &alg);
|
193
|
+
if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
|
194
|
+
BIO_free(out);
|
195
|
+
ossl_raise(eX509CRLError, NULL);
|
196
|
+
}
|
197
|
+
BIO_get_mem_ptr(out, &buf);
|
198
|
+
str = rb_str_new(buf->data, buf->length);
|
199
|
+
BIO_free(out);
|
200
|
+
return str;
|
201
|
+
}
|
202
|
+
|
203
|
+
static VALUE
|
204
|
+
ossl_x509crl_get_issuer(VALUE self)
|
205
|
+
{
|
206
|
+
X509_CRL *crl;
|
207
|
+
|
208
|
+
GetX509CRL(self, crl);
|
209
|
+
|
210
|
+
return ossl_x509name_new(X509_CRL_get_issuer(crl)); /* NO DUP - don't free */
|
211
|
+
}
|
212
|
+
|
213
|
+
static VALUE
|
214
|
+
ossl_x509crl_set_issuer(VALUE self, VALUE issuer)
|
215
|
+
{
|
216
|
+
X509_CRL *crl;
|
217
|
+
|
218
|
+
GetX509CRL(self, crl);
|
219
|
+
|
220
|
+
if (!X509_CRL_set_issuer_name(crl, GetX509NamePtr(issuer))) { /* DUPs name */
|
221
|
+
ossl_raise(eX509CRLError, NULL);
|
222
|
+
}
|
223
|
+
return issuer;
|
224
|
+
}
|
225
|
+
|
226
|
+
static VALUE
|
227
|
+
ossl_x509crl_get_last_update(VALUE self)
|
228
|
+
{
|
229
|
+
X509_CRL *crl;
|
230
|
+
|
231
|
+
GetX509CRL(self, crl);
|
232
|
+
|
233
|
+
return asn1time_to_time(X509_CRL_get0_lastUpdate(crl));
|
234
|
+
}
|
235
|
+
|
236
|
+
static VALUE
|
237
|
+
ossl_x509crl_set_last_update(VALUE self, VALUE time)
|
238
|
+
{
|
239
|
+
X509_CRL *crl;
|
240
|
+
ASN1_TIME *asn1time;
|
241
|
+
|
242
|
+
GetX509CRL(self, crl);
|
243
|
+
asn1time = ossl_x509_time_adjust(NULL, time);
|
244
|
+
if (!X509_CRL_set_lastUpdate(crl, asn1time)) {
|
245
|
+
ASN1_TIME_free(asn1time);
|
246
|
+
ossl_raise(eX509CRLError, "X509_CRL_set_lastUpdate");
|
247
|
+
}
|
248
|
+
ASN1_TIME_free(asn1time);
|
249
|
+
|
250
|
+
return time;
|
251
|
+
}
|
252
|
+
|
253
|
+
static VALUE
|
254
|
+
ossl_x509crl_get_next_update(VALUE self)
|
255
|
+
{
|
256
|
+
X509_CRL *crl;
|
257
|
+
|
258
|
+
GetX509CRL(self, crl);
|
259
|
+
|
260
|
+
return asn1time_to_time(X509_CRL_get0_nextUpdate(crl));
|
261
|
+
}
|
262
|
+
|
263
|
+
static VALUE
|
264
|
+
ossl_x509crl_set_next_update(VALUE self, VALUE time)
|
265
|
+
{
|
266
|
+
X509_CRL *crl;
|
267
|
+
ASN1_TIME *asn1time;
|
268
|
+
|
269
|
+
GetX509CRL(self, crl);
|
270
|
+
asn1time = ossl_x509_time_adjust(NULL, time);
|
271
|
+
if (!X509_CRL_set_nextUpdate(crl, asn1time)) {
|
272
|
+
ASN1_TIME_free(asn1time);
|
273
|
+
ossl_raise(eX509CRLError, "X509_CRL_set_nextUpdate");
|
274
|
+
}
|
275
|
+
ASN1_TIME_free(asn1time);
|
276
|
+
|
277
|
+
return time;
|
278
|
+
}
|
279
|
+
|
280
|
+
static VALUE
|
281
|
+
ossl_x509crl_get_revoked(VALUE self)
|
282
|
+
{
|
283
|
+
X509_CRL *crl;
|
284
|
+
int i, num;
|
285
|
+
X509_REVOKED *rev;
|
286
|
+
VALUE ary, revoked;
|
287
|
+
|
288
|
+
GetX509CRL(self, crl);
|
289
|
+
num = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
|
290
|
+
if (num < 0) {
|
291
|
+
OSSL_Debug("num < 0???");
|
292
|
+
return rb_ary_new();
|
293
|
+
}
|
294
|
+
ary = rb_ary_new2(num);
|
295
|
+
for(i=0; i<num; i++) {
|
296
|
+
/* NO DUP - don't free! */
|
297
|
+
rev = sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
|
298
|
+
revoked = ossl_x509revoked_new(rev);
|
299
|
+
rb_ary_push(ary, revoked);
|
300
|
+
}
|
301
|
+
|
302
|
+
return ary;
|
303
|
+
}
|
304
|
+
|
305
|
+
static VALUE
|
306
|
+
ossl_x509crl_set_revoked(VALUE self, VALUE ary)
|
307
|
+
{
|
308
|
+
X509_CRL *crl;
|
309
|
+
X509_REVOKED *rev;
|
310
|
+
STACK_OF(X509_REVOKED) *sk;
|
311
|
+
long i;
|
312
|
+
|
313
|
+
Check_Type(ary, T_ARRAY);
|
314
|
+
/* All ary members should be X509 Revoked */
|
315
|
+
for (i=0; i<RARRAY_LEN(ary); i++) {
|
316
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Rev);
|
317
|
+
}
|
318
|
+
GetX509CRL(self, crl);
|
319
|
+
if ((sk = X509_CRL_get_REVOKED(crl))) {
|
320
|
+
while ((rev = sk_X509_REVOKED_pop(sk)))
|
321
|
+
X509_REVOKED_free(rev);
|
322
|
+
}
|
323
|
+
for (i=0; i<RARRAY_LEN(ary); i++) {
|
324
|
+
rev = DupX509RevokedPtr(RARRAY_AREF(ary, i));
|
325
|
+
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
|
326
|
+
X509_REVOKED_free(rev);
|
327
|
+
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
|
328
|
+
}
|
329
|
+
}
|
330
|
+
X509_CRL_sort(crl);
|
331
|
+
|
332
|
+
return ary;
|
333
|
+
}
|
334
|
+
|
335
|
+
static VALUE
|
336
|
+
ossl_x509crl_add_revoked(VALUE self, VALUE revoked)
|
337
|
+
{
|
338
|
+
X509_CRL *crl;
|
339
|
+
X509_REVOKED *rev;
|
340
|
+
|
341
|
+
GetX509CRL(self, crl);
|
342
|
+
rev = DupX509RevokedPtr(revoked);
|
343
|
+
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
|
344
|
+
X509_REVOKED_free(rev);
|
345
|
+
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
|
346
|
+
}
|
347
|
+
X509_CRL_sort(crl);
|
348
|
+
|
349
|
+
return revoked;
|
350
|
+
}
|
351
|
+
|
352
|
+
static VALUE
|
353
|
+
ossl_x509crl_sign(VALUE self, VALUE key, VALUE digest)
|
354
|
+
{
|
355
|
+
X509_CRL *crl;
|
356
|
+
EVP_PKEY *pkey;
|
357
|
+
const EVP_MD *md;
|
358
|
+
|
359
|
+
GetX509CRL(self, crl);
|
360
|
+
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
361
|
+
md = GetDigestPtr(digest);
|
362
|
+
if (!X509_CRL_sign(crl, pkey, md)) {
|
363
|
+
ossl_raise(eX509CRLError, NULL);
|
364
|
+
}
|
365
|
+
|
366
|
+
return self;
|
367
|
+
}
|
368
|
+
|
369
|
+
static VALUE
|
370
|
+
ossl_x509crl_verify(VALUE self, VALUE key)
|
371
|
+
{
|
372
|
+
X509_CRL *crl;
|
373
|
+
|
374
|
+
GetX509CRL(self, crl);
|
375
|
+
switch (X509_CRL_verify(crl, GetPKeyPtr(key))) {
|
376
|
+
case 1:
|
377
|
+
return Qtrue;
|
378
|
+
case 0:
|
379
|
+
ossl_clear_error();
|
380
|
+
return Qfalse;
|
381
|
+
default:
|
382
|
+
ossl_raise(eX509CRLError, NULL);
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
static VALUE
|
387
|
+
ossl_x509crl_to_der(VALUE self)
|
388
|
+
{
|
389
|
+
X509_CRL *crl;
|
390
|
+
BIO *out;
|
391
|
+
BUF_MEM *buf;
|
392
|
+
VALUE str;
|
393
|
+
|
394
|
+
GetX509CRL(self, crl);
|
395
|
+
if (!(out = BIO_new(BIO_s_mem()))) {
|
396
|
+
ossl_raise(eX509CRLError, NULL);
|
397
|
+
}
|
398
|
+
if (!i2d_X509_CRL_bio(out, crl)) {
|
399
|
+
BIO_free(out);
|
400
|
+
ossl_raise(eX509CRLError, NULL);
|
401
|
+
}
|
402
|
+
BIO_get_mem_ptr(out, &buf);
|
403
|
+
str = rb_str_new(buf->data, buf->length);
|
404
|
+
BIO_free(out);
|
405
|
+
|
406
|
+
return str;
|
407
|
+
}
|
408
|
+
|
409
|
+
static VALUE
|
410
|
+
ossl_x509crl_to_pem(VALUE self)
|
411
|
+
{
|
412
|
+
X509_CRL *crl;
|
413
|
+
BIO *out;
|
414
|
+
BUF_MEM *buf;
|
415
|
+
VALUE str;
|
416
|
+
|
417
|
+
GetX509CRL(self, crl);
|
418
|
+
if (!(out = BIO_new(BIO_s_mem()))) {
|
419
|
+
ossl_raise(eX509CRLError, NULL);
|
420
|
+
}
|
421
|
+
if (!PEM_write_bio_X509_CRL(out, crl)) {
|
422
|
+
BIO_free(out);
|
423
|
+
ossl_raise(eX509CRLError, NULL);
|
424
|
+
}
|
425
|
+
BIO_get_mem_ptr(out, &buf);
|
426
|
+
str = rb_str_new(buf->data, buf->length);
|
427
|
+
BIO_free(out);
|
428
|
+
|
429
|
+
return str;
|
430
|
+
}
|
431
|
+
|
432
|
+
static VALUE
|
433
|
+
ossl_x509crl_to_text(VALUE self)
|
434
|
+
{
|
435
|
+
X509_CRL *crl;
|
436
|
+
BIO *out;
|
437
|
+
BUF_MEM *buf;
|
438
|
+
VALUE str;
|
439
|
+
|
440
|
+
GetX509CRL(self, crl);
|
441
|
+
if (!(out = BIO_new(BIO_s_mem()))) {
|
442
|
+
ossl_raise(eX509CRLError, NULL);
|
443
|
+
}
|
444
|
+
if (!X509_CRL_print(out, crl)) {
|
445
|
+
BIO_free(out);
|
446
|
+
ossl_raise(eX509CRLError, NULL);
|
447
|
+
}
|
448
|
+
BIO_get_mem_ptr(out, &buf);
|
449
|
+
str = rb_str_new(buf->data, buf->length);
|
450
|
+
BIO_free(out);
|
451
|
+
|
452
|
+
return str;
|
453
|
+
}
|
454
|
+
|
455
|
+
/*
|
456
|
+
* Gets X509v3 extensions as array of X509Ext objects
|
457
|
+
*/
|
458
|
+
static VALUE
|
459
|
+
ossl_x509crl_get_extensions(VALUE self)
|
460
|
+
{
|
461
|
+
X509_CRL *crl;
|
462
|
+
int count, i;
|
463
|
+
X509_EXTENSION *ext;
|
464
|
+
VALUE ary;
|
465
|
+
|
466
|
+
GetX509CRL(self, crl);
|
467
|
+
count = X509_CRL_get_ext_count(crl);
|
468
|
+
if (count < 0) {
|
469
|
+
OSSL_Debug("count < 0???");
|
470
|
+
return rb_ary_new();
|
471
|
+
}
|
472
|
+
ary = rb_ary_new2(count);
|
473
|
+
for (i=0; i<count; i++) {
|
474
|
+
ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */
|
475
|
+
rb_ary_push(ary, ossl_x509ext_new(ext));
|
476
|
+
}
|
477
|
+
|
478
|
+
return ary;
|
479
|
+
}
|
480
|
+
|
481
|
+
/*
|
482
|
+
* Sets X509_EXTENSIONs
|
483
|
+
*/
|
484
|
+
static VALUE
|
485
|
+
ossl_x509crl_set_extensions(VALUE self, VALUE ary)
|
486
|
+
{
|
487
|
+
X509_CRL *crl;
|
488
|
+
X509_EXTENSION *ext;
|
489
|
+
long i;
|
490
|
+
|
491
|
+
Check_Type(ary, T_ARRAY);
|
492
|
+
/* All ary members should be X509 Extensions */
|
493
|
+
for (i=0; i<RARRAY_LEN(ary); i++) {
|
494
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
|
495
|
+
}
|
496
|
+
GetX509CRL(self, crl);
|
497
|
+
while ((ext = X509_CRL_delete_ext(crl, 0)))
|
498
|
+
X509_EXTENSION_free(ext);
|
499
|
+
for (i=0; i<RARRAY_LEN(ary); i++) {
|
500
|
+
ext = GetX509ExtPtr(RARRAY_AREF(ary, i)); /* NO NEED TO DUP */
|
501
|
+
if (!X509_CRL_add_ext(crl, ext, -1)) {
|
502
|
+
ossl_raise(eX509CRLError, NULL);
|
503
|
+
}
|
504
|
+
}
|
505
|
+
|
506
|
+
return ary;
|
507
|
+
}
|
508
|
+
|
509
|
+
static VALUE
|
510
|
+
ossl_x509crl_add_extension(VALUE self, VALUE extension)
|
511
|
+
{
|
512
|
+
X509_CRL *crl;
|
513
|
+
X509_EXTENSION *ext;
|
514
|
+
|
515
|
+
GetX509CRL(self, crl);
|
516
|
+
ext = GetX509ExtPtr(extension);
|
517
|
+
if (!X509_CRL_add_ext(crl, ext, -1)) {
|
518
|
+
ossl_raise(eX509CRLError, NULL);
|
519
|
+
}
|
520
|
+
|
521
|
+
return extension;
|
522
|
+
}
|
523
|
+
|
524
|
+
/*
|
525
|
+
* INIT
|
526
|
+
*/
|
527
|
+
void
|
528
|
+
Init_ossl_x509crl(void)
|
529
|
+
{
|
530
|
+
#if 0
|
531
|
+
mOSSL = rb_define_module("OpenSSL");
|
532
|
+
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
533
|
+
mX509 = rb_define_module_under(mOSSL, "X509");
|
534
|
+
#endif
|
535
|
+
|
536
|
+
eX509CRLError = rb_define_class_under(mX509, "CRLError", eOSSLError);
|
537
|
+
|
538
|
+
cX509CRL = rb_define_class_under(mX509, "CRL", rb_cObject);
|
539
|
+
|
540
|
+
rb_define_alloc_func(cX509CRL, ossl_x509crl_alloc);
|
541
|
+
rb_define_method(cX509CRL, "initialize", ossl_x509crl_initialize, -1);
|
542
|
+
rb_define_copy_func(cX509CRL, ossl_x509crl_copy);
|
543
|
+
|
544
|
+
rb_define_method(cX509CRL, "version", ossl_x509crl_get_version, 0);
|
545
|
+
rb_define_method(cX509CRL, "version=", ossl_x509crl_set_version, 1);
|
546
|
+
rb_define_method(cX509CRL, "signature_algorithm", ossl_x509crl_get_signature_algorithm, 0);
|
547
|
+
rb_define_method(cX509CRL, "issuer", ossl_x509crl_get_issuer, 0);
|
548
|
+
rb_define_method(cX509CRL, "issuer=", ossl_x509crl_set_issuer, 1);
|
549
|
+
rb_define_method(cX509CRL, "last_update", ossl_x509crl_get_last_update, 0);
|
550
|
+
rb_define_method(cX509CRL, "last_update=", ossl_x509crl_set_last_update, 1);
|
551
|
+
rb_define_method(cX509CRL, "next_update", ossl_x509crl_get_next_update, 0);
|
552
|
+
rb_define_method(cX509CRL, "next_update=", ossl_x509crl_set_next_update, 1);
|
553
|
+
rb_define_method(cX509CRL, "revoked", ossl_x509crl_get_revoked, 0);
|
554
|
+
rb_define_method(cX509CRL, "revoked=", ossl_x509crl_set_revoked, 1);
|
555
|
+
rb_define_method(cX509CRL, "add_revoked", ossl_x509crl_add_revoked, 1);
|
556
|
+
rb_define_method(cX509CRL, "sign", ossl_x509crl_sign, 2);
|
557
|
+
rb_define_method(cX509CRL, "verify", ossl_x509crl_verify, 1);
|
558
|
+
rb_define_method(cX509CRL, "to_der", ossl_x509crl_to_der, 0);
|
559
|
+
rb_define_method(cX509CRL, "to_pem", ossl_x509crl_to_pem, 0);
|
560
|
+
rb_define_alias(cX509CRL, "to_s", "to_pem");
|
561
|
+
rb_define_method(cX509CRL, "to_text", ossl_x509crl_to_text, 0);
|
562
|
+
rb_define_method(cX509CRL, "extensions", ossl_x509crl_get_extensions, 0);
|
563
|
+
rb_define_method(cX509CRL, "extensions=", ossl_x509crl_set_extensions, 1);
|
564
|
+
rb_define_method(cX509CRL, "add_extension", ossl_x509crl_add_extension, 1);
|
565
|
+
}
|