openssl 3.3.2 → 4.0.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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +3 -0
- data/History.md +85 -0
- data/README.md +12 -11
- data/ext/openssl/extconf.rb +30 -69
- data/ext/openssl/openssl_missing.h +0 -206
- data/ext/openssl/ossl.c +280 -301
- data/ext/openssl/ossl.h +15 -10
- data/ext/openssl/ossl_asn1.c +598 -406
- data/ext/openssl/ossl_asn1.h +15 -1
- data/ext/openssl/ossl_bio.c +3 -3
- data/ext/openssl/ossl_bn.c +286 -291
- data/ext/openssl/ossl_cipher.c +252 -203
- data/ext/openssl/ossl_cipher.h +10 -1
- data/ext/openssl/ossl_config.c +1 -6
- data/ext/openssl/ossl_digest.c +74 -43
- data/ext/openssl/ossl_digest.h +9 -1
- data/ext/openssl/ossl_engine.c +39 -103
- data/ext/openssl/ossl_hmac.c +30 -36
- data/ext/openssl/ossl_kdf.c +42 -53
- data/ext/openssl/ossl_ns_spki.c +31 -37
- data/ext/openssl/ossl_ocsp.c +214 -241
- data/ext/openssl/ossl_pkcs12.c +26 -26
- data/ext/openssl/ossl_pkcs7.c +175 -145
- data/ext/openssl/ossl_pkey.c +162 -178
- data/ext/openssl/ossl_pkey.h +99 -99
- data/ext/openssl/ossl_pkey_dh.c +31 -68
- data/ext/openssl/ossl_pkey_dsa.c +15 -54
- data/ext/openssl/ossl_pkey_ec.c +179 -237
- data/ext/openssl/ossl_pkey_rsa.c +56 -103
- data/ext/openssl/ossl_provider.c +0 -7
- data/ext/openssl/ossl_rand.c +7 -14
- data/ext/openssl/ossl_ssl.c +478 -353
- data/ext/openssl/ossl_ssl.h +8 -8
- data/ext/openssl/ossl_ssl_session.c +93 -97
- data/ext/openssl/ossl_ts.c +81 -127
- data/ext/openssl/ossl_x509.c +9 -28
- data/ext/openssl/ossl_x509attr.c +33 -54
- data/ext/openssl/ossl_x509cert.c +69 -100
- data/ext/openssl/ossl_x509crl.c +78 -89
- data/ext/openssl/ossl_x509ext.c +45 -66
- data/ext/openssl/ossl_x509name.c +63 -88
- data/ext/openssl/ossl_x509req.c +55 -62
- data/ext/openssl/ossl_x509revoked.c +27 -41
- data/ext/openssl/ossl_x509store.c +38 -56
- data/lib/openssl/buffering.rb +30 -24
- data/lib/openssl/digest.rb +1 -1
- data/lib/openssl/pkey.rb +71 -49
- data/lib/openssl/ssl.rb +12 -79
- data/lib/openssl/version.rb +2 -1
- data/lib/openssl/x509.rb +9 -0
- data/lib/openssl.rb +9 -6
- metadata +1 -3
- data/ext/openssl/openssl_missing.c +0 -40
- data/lib/openssl/asn1.rb +0 -188
data/ext/openssl/ossl_x509crl.c
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509crl_type, 0)
|
|
14
14
|
#define SetX509CRL(obj, crl) do { \
|
|
15
15
|
if (!(crl)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (crl); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509CRL(obj, crl) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_CRL, &ossl_x509crl_type, (crl)); \
|
|
22
22
|
if (!(crl)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "CRL wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ ossl_x509crl_free(void *ptr)
|
|
|
39
39
|
static const rb_data_type_t ossl_x509crl_type = {
|
|
40
40
|
"OpenSSL/X509/CRL",
|
|
41
41
|
{
|
|
42
|
-
|
|
42
|
+
0, ossl_x509crl_free,
|
|
43
43
|
},
|
|
44
44
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
45
45
|
};
|
|
@@ -64,8 +64,9 @@ ossl_x509crl_new(X509_CRL *crl)
|
|
|
64
64
|
VALUE obj;
|
|
65
65
|
|
|
66
66
|
obj = NewX509CRL(cX509CRL);
|
|
67
|
-
tmp =
|
|
68
|
-
if(!tmp)
|
|
67
|
+
tmp = X509_CRL_dup(crl);
|
|
68
|
+
if (!tmp)
|
|
69
|
+
ossl_raise(eX509CRLError, "X509_CRL_dup");
|
|
69
70
|
SetX509CRL(obj, tmp);
|
|
70
71
|
|
|
71
72
|
return obj;
|
|
@@ -82,7 +83,7 @@ ossl_x509crl_alloc(VALUE klass)
|
|
|
82
83
|
|
|
83
84
|
obj = NewX509CRL(klass);
|
|
84
85
|
if (!(crl = X509_CRL_new())) {
|
|
85
|
-
|
|
86
|
+
ossl_raise(eX509CRLError, NULL);
|
|
86
87
|
}
|
|
87
88
|
SetX509CRL(obj, crl);
|
|
88
89
|
|
|
@@ -98,7 +99,7 @@ ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
98
99
|
|
|
99
100
|
rb_check_frozen(self);
|
|
100
101
|
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
|
|
101
|
-
|
|
102
|
+
return self;
|
|
102
103
|
}
|
|
103
104
|
arg = ossl_to_der_if_possible(arg);
|
|
104
105
|
in = ossl_obj2bio(&arg);
|
|
@@ -117,6 +118,7 @@ ossl_x509crl_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
117
118
|
return self;
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
/* :nodoc: */
|
|
120
122
|
static VALUE
|
|
121
123
|
ossl_x509crl_copy(VALUE self, VALUE other)
|
|
122
124
|
{
|
|
@@ -127,7 +129,7 @@ ossl_x509crl_copy(VALUE self, VALUE other)
|
|
|
127
129
|
GetX509CRL(self, a);
|
|
128
130
|
GetX509CRL(other, b);
|
|
129
131
|
if (!(crl = X509_CRL_dup(b))) {
|
|
130
|
-
|
|
132
|
+
ossl_raise(eX509CRLError, NULL);
|
|
131
133
|
}
|
|
132
134
|
X509_CRL_free(a);
|
|
133
135
|
DATA_PTR(self) = crl;
|
|
@@ -154,34 +156,36 @@ ossl_x509crl_set_version(VALUE self, VALUE version)
|
|
|
154
156
|
long ver;
|
|
155
157
|
|
|
156
158
|
if ((ver = NUM2LONG(version)) < 0) {
|
|
157
|
-
|
|
159
|
+
ossl_raise(eX509CRLError, "version must be >= 0!");
|
|
158
160
|
}
|
|
159
161
|
GetX509CRL(self, crl);
|
|
160
162
|
if (!X509_CRL_set_version(crl, ver)) {
|
|
161
|
-
|
|
163
|
+
ossl_raise(eX509CRLError, NULL);
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
return version;
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
/*
|
|
170
|
+
* call-seq:
|
|
171
|
+
* crl.signature_algorithm -> string
|
|
172
|
+
*
|
|
173
|
+
* Returns the signature algorithm used to sign this CRL.
|
|
174
|
+
*
|
|
175
|
+
* Returns the long name of the signature algorithm, or the dotted decimal
|
|
176
|
+
* notation if \OpenSSL does not define a long name for it.
|
|
177
|
+
*/
|
|
167
178
|
static VALUE
|
|
168
179
|
ossl_x509crl_get_signature_algorithm(VALUE self)
|
|
169
180
|
{
|
|
170
181
|
X509_CRL *crl;
|
|
171
182
|
const X509_ALGOR *alg;
|
|
172
|
-
|
|
183
|
+
const ASN1_OBJECT *obj;
|
|
173
184
|
|
|
174
185
|
GetX509CRL(self, crl);
|
|
175
|
-
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
176
|
-
ossl_raise(eX509CRLError, NULL);
|
|
177
|
-
}
|
|
178
186
|
X509_CRL_get0_signature(crl, NULL, &alg);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
ossl_raise(eX509CRLError, NULL);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return ossl_membio2str(out);
|
|
187
|
+
X509_ALGOR_get0(&obj, NULL, NULL, alg);
|
|
188
|
+
return ossl_asn1obj_to_string_long_name(obj);
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
static VALUE
|
|
@@ -202,7 +206,7 @@ ossl_x509crl_set_issuer(VALUE self, VALUE issuer)
|
|
|
202
206
|
GetX509CRL(self, crl);
|
|
203
207
|
|
|
204
208
|
if (!X509_CRL_set_issuer_name(crl, GetX509NamePtr(issuer))) { /* DUPs name */
|
|
205
|
-
|
|
209
|
+
ossl_raise(eX509CRLError, NULL);
|
|
206
210
|
}
|
|
207
211
|
return issuer;
|
|
208
212
|
}
|
|
@@ -216,7 +220,7 @@ ossl_x509crl_get_last_update(VALUE self)
|
|
|
216
220
|
GetX509CRL(self, crl);
|
|
217
221
|
time = X509_CRL_get0_lastUpdate(crl);
|
|
218
222
|
if (!time)
|
|
219
|
-
|
|
223
|
+
return Qnil;
|
|
220
224
|
|
|
221
225
|
return asn1time_to_time(time);
|
|
222
226
|
}
|
|
@@ -230,8 +234,8 @@ ossl_x509crl_set_last_update(VALUE self, VALUE time)
|
|
|
230
234
|
GetX509CRL(self, crl);
|
|
231
235
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
|
232
236
|
if (!X509_CRL_set1_lastUpdate(crl, asn1time)) {
|
|
233
|
-
|
|
234
|
-
|
|
237
|
+
ASN1_TIME_free(asn1time);
|
|
238
|
+
ossl_raise(eX509CRLError, "X509_CRL_set_lastUpdate");
|
|
235
239
|
}
|
|
236
240
|
ASN1_TIME_free(asn1time);
|
|
237
241
|
|
|
@@ -247,7 +251,7 @@ ossl_x509crl_get_next_update(VALUE self)
|
|
|
247
251
|
GetX509CRL(self, crl);
|
|
248
252
|
time = X509_CRL_get0_nextUpdate(crl);
|
|
249
253
|
if (!time)
|
|
250
|
-
|
|
254
|
+
return Qnil;
|
|
251
255
|
|
|
252
256
|
return asn1time_to_time(time);
|
|
253
257
|
}
|
|
@@ -261,8 +265,8 @@ ossl_x509crl_set_next_update(VALUE self, VALUE time)
|
|
|
261
265
|
GetX509CRL(self, crl);
|
|
262
266
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
|
263
267
|
if (!X509_CRL_set1_nextUpdate(crl, asn1time)) {
|
|
264
|
-
|
|
265
|
-
|
|
268
|
+
ASN1_TIME_free(asn1time);
|
|
269
|
+
ossl_raise(eX509CRLError, "X509_CRL_set_nextUpdate");
|
|
266
270
|
}
|
|
267
271
|
ASN1_TIME_free(asn1time);
|
|
268
272
|
|
|
@@ -274,21 +278,19 @@ ossl_x509crl_get_revoked(VALUE self)
|
|
|
274
278
|
{
|
|
275
279
|
X509_CRL *crl;
|
|
276
280
|
int i, num;
|
|
277
|
-
X509_REVOKED *
|
|
278
|
-
VALUE ary
|
|
281
|
+
STACK_OF(X509_REVOKED) *sk;
|
|
282
|
+
VALUE ary;
|
|
279
283
|
|
|
280
284
|
GetX509CRL(self, crl);
|
|
281
|
-
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
ary =
|
|
285
|
+
sk = X509_CRL_get_REVOKED(crl);
|
|
286
|
+
if (!sk)
|
|
287
|
+
return rb_ary_new();
|
|
288
|
+
|
|
289
|
+
num = sk_X509_REVOKED_num(sk);
|
|
290
|
+
ary = rb_ary_new_capa(num);
|
|
287
291
|
for(i=0; i<num; i++) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
revoked = ossl_x509revoked_new(rev);
|
|
291
|
-
rb_ary_push(ary, revoked);
|
|
292
|
+
X509_REVOKED *rev = sk_X509_REVOKED_value(sk, i);
|
|
293
|
+
rb_ary_push(ary, ossl_x509revoked_new(rev));
|
|
292
294
|
}
|
|
293
295
|
|
|
294
296
|
return ary;
|
|
@@ -305,19 +307,19 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
|
|
|
305
307
|
Check_Type(ary, T_ARRAY);
|
|
306
308
|
/* All ary members should be X509 Revoked */
|
|
307
309
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
308
|
-
|
|
310
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Rev);
|
|
309
311
|
}
|
|
310
312
|
GetX509CRL(self, crl);
|
|
311
313
|
if ((sk = X509_CRL_get_REVOKED(crl))) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
+
while ((rev = sk_X509_REVOKED_pop(sk)))
|
|
315
|
+
X509_REVOKED_free(rev);
|
|
314
316
|
}
|
|
315
317
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
rev = DupX509RevokedPtr(RARRAY_AREF(ary, i));
|
|
319
|
+
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
|
|
320
|
+
X509_REVOKED_free(rev);
|
|
321
|
+
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
|
|
322
|
+
}
|
|
321
323
|
}
|
|
322
324
|
X509_CRL_sort(crl);
|
|
323
325
|
|
|
@@ -333,8 +335,8 @@ ossl_x509crl_add_revoked(VALUE self, VALUE revoked)
|
|
|
333
335
|
GetX509CRL(self, crl);
|
|
334
336
|
rev = DupX509RevokedPtr(revoked);
|
|
335
337
|
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
|
|
336
|
-
|
|
337
|
-
|
|
338
|
+
X509_REVOKED_free(rev);
|
|
339
|
+
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
|
|
338
340
|
}
|
|
339
341
|
X509_CRL_sort(crl);
|
|
340
342
|
|
|
@@ -347,17 +349,14 @@ ossl_x509crl_sign(VALUE self, VALUE key, VALUE digest)
|
|
|
347
349
|
X509_CRL *crl;
|
|
348
350
|
EVP_PKEY *pkey;
|
|
349
351
|
const EVP_MD *md;
|
|
352
|
+
VALUE md_holder;
|
|
350
353
|
|
|
351
354
|
GetX509CRL(self, crl);
|
|
352
355
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
if (!X509_CRL_sign(crl, pkey, md)) {
|
|
359
|
-
ossl_raise(eX509CRLError, NULL);
|
|
360
|
-
}
|
|
356
|
+
/* NULL needed for some key types, e.g. Ed25519 */
|
|
357
|
+
md = NIL_P(digest) ? NULL : ossl_evp_md_fetch(digest, &md_holder);
|
|
358
|
+
if (!X509_CRL_sign(crl, pkey, md))
|
|
359
|
+
ossl_raise(eX509CRLError, "X509_CRL_sign");
|
|
361
360
|
|
|
362
361
|
return self;
|
|
363
362
|
}
|
|
@@ -373,12 +372,12 @@ ossl_x509crl_verify(VALUE self, VALUE key)
|
|
|
373
372
|
ossl_pkey_check_public_key(pkey);
|
|
374
373
|
switch (X509_CRL_verify(crl, pkey)) {
|
|
375
374
|
case 1:
|
|
376
|
-
|
|
375
|
+
return Qtrue;
|
|
377
376
|
case 0:
|
|
378
|
-
|
|
379
|
-
|
|
377
|
+
ossl_clear_error();
|
|
378
|
+
return Qfalse;
|
|
380
379
|
default:
|
|
381
|
-
|
|
380
|
+
ossl_raise(eX509CRLError, NULL);
|
|
382
381
|
}
|
|
383
382
|
}
|
|
384
383
|
|
|
@@ -390,11 +389,11 @@ ossl_x509crl_to_der(VALUE self)
|
|
|
390
389
|
|
|
391
390
|
GetX509CRL(self, crl);
|
|
392
391
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
393
|
-
|
|
392
|
+
ossl_raise(eX509CRLError, NULL);
|
|
394
393
|
}
|
|
395
394
|
if (!i2d_X509_CRL_bio(out, crl)) {
|
|
396
|
-
|
|
397
|
-
|
|
395
|
+
BIO_free(out);
|
|
396
|
+
ossl_raise(eX509CRLError, NULL);
|
|
398
397
|
}
|
|
399
398
|
|
|
400
399
|
return ossl_membio2str(out);
|
|
@@ -408,11 +407,11 @@ ossl_x509crl_to_pem(VALUE self)
|
|
|
408
407
|
|
|
409
408
|
GetX509CRL(self, crl);
|
|
410
409
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
411
|
-
|
|
410
|
+
ossl_raise(eX509CRLError, NULL);
|
|
412
411
|
}
|
|
413
412
|
if (!PEM_write_bio_X509_CRL(out, crl)) {
|
|
414
|
-
|
|
415
|
-
|
|
413
|
+
BIO_free(out);
|
|
414
|
+
ossl_raise(eX509CRLError, NULL);
|
|
416
415
|
}
|
|
417
416
|
|
|
418
417
|
return ossl_membio2str(out);
|
|
@@ -426,11 +425,11 @@ ossl_x509crl_to_text(VALUE self)
|
|
|
426
425
|
|
|
427
426
|
GetX509CRL(self, crl);
|
|
428
427
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
429
|
-
|
|
428
|
+
ossl_raise(eX509CRLError, NULL);
|
|
430
429
|
}
|
|
431
430
|
if (!X509_CRL_print(out, crl)) {
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
BIO_free(out);
|
|
432
|
+
ossl_raise(eX509CRLError, NULL);
|
|
434
433
|
}
|
|
435
434
|
|
|
436
435
|
return ossl_membio2str(out);
|
|
@@ -449,14 +448,10 @@ ossl_x509crl_get_extensions(VALUE self)
|
|
|
449
448
|
|
|
450
449
|
GetX509CRL(self, crl);
|
|
451
450
|
count = X509_CRL_get_ext_count(crl);
|
|
452
|
-
|
|
453
|
-
OSSL_Debug("count < 0???");
|
|
454
|
-
return rb_ary_new();
|
|
455
|
-
}
|
|
456
|
-
ary = rb_ary_new2(count);
|
|
451
|
+
ary = rb_ary_new_capa(count);
|
|
457
452
|
for (i=0; i<count; i++) {
|
|
458
|
-
|
|
459
|
-
|
|
453
|
+
ext = X509_CRL_get_ext(crl, i); /* NO DUP - don't free! */
|
|
454
|
+
rb_ary_push(ary, ossl_x509ext_new(ext));
|
|
460
455
|
}
|
|
461
456
|
|
|
462
457
|
return ary;
|
|
@@ -475,16 +470,16 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
|
|
|
475
470
|
Check_Type(ary, T_ARRAY);
|
|
476
471
|
/* All ary members should be X509 Extensions */
|
|
477
472
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
478
|
-
|
|
473
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
|
|
479
474
|
}
|
|
480
475
|
GetX509CRL(self, crl);
|
|
481
476
|
for (i = X509_CRL_get_ext_count(crl); i > 0; i--)
|
|
482
477
|
X509_EXTENSION_free(X509_CRL_delete_ext(crl, 0));
|
|
483
478
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
479
|
+
ext = GetX509ExtPtr(RARRAY_AREF(ary, i)); /* NO NEED TO DUP */
|
|
480
|
+
if (!X509_CRL_add_ext(crl, ext, -1)) {
|
|
481
|
+
ossl_raise(eX509CRLError, "X509_CRL_add_ext");
|
|
482
|
+
}
|
|
488
483
|
}
|
|
489
484
|
|
|
490
485
|
return ary;
|
|
@@ -499,7 +494,7 @@ ossl_x509crl_add_extension(VALUE self, VALUE extension)
|
|
|
499
494
|
GetX509CRL(self, crl);
|
|
500
495
|
ext = GetX509ExtPtr(extension);
|
|
501
496
|
if (!X509_CRL_add_ext(crl, ext, -1)) {
|
|
502
|
-
|
|
497
|
+
ossl_raise(eX509CRLError, NULL);
|
|
503
498
|
}
|
|
504
499
|
|
|
505
500
|
return extension;
|
|
@@ -511,12 +506,6 @@ ossl_x509crl_add_extension(VALUE self, VALUE extension)
|
|
|
511
506
|
void
|
|
512
507
|
Init_ossl_x509crl(void)
|
|
513
508
|
{
|
|
514
|
-
#if 0
|
|
515
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
516
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
517
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
518
|
-
#endif
|
|
519
|
-
|
|
520
509
|
eX509CRLError = rb_define_class_under(mX509, "CRLError", eOSSLError);
|
|
521
510
|
|
|
522
511
|
cX509CRL = rb_define_class_under(mX509, "CRL", rb_cObject);
|
data/ext/openssl/ossl_x509ext.c
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509ext_type, 0)
|
|
14
14
|
#define SetX509Ext(obj, ext) do { \
|
|
15
15
|
if (!(ext)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (ext); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509Ext(obj, ext) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_EXTENSION, &ossl_x509ext_type, (ext)); \
|
|
22
22
|
if (!(ext)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
#define MakeX509ExtFactory(klass, obj, ctx) do { \
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
#define GetX509ExtFactory(obj, ctx) do { \
|
|
34
34
|
TypedData_Get_Struct((obj), X509V3_CTX, &ossl_x509extfactory_type, (ctx)); \
|
|
35
35
|
if (!(ctx)) { \
|
|
36
|
-
|
|
36
|
+
ossl_raise(rb_eRuntimeError, "CTX wasn't initialized!"); \
|
|
37
37
|
} \
|
|
38
38
|
} while (0)
|
|
39
39
|
|
|
@@ -53,7 +53,7 @@ ossl_x509ext_free(void *ptr)
|
|
|
53
53
|
static const rb_data_type_t ossl_x509ext_type = {
|
|
54
54
|
"OpenSSL/X509/EXTENSION",
|
|
55
55
|
{
|
|
56
|
-
|
|
56
|
+
0, ossl_x509ext_free,
|
|
57
57
|
},
|
|
58
58
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
59
59
|
};
|
|
@@ -68,14 +68,9 @@ ossl_x509ext_new(X509_EXTENSION *ext)
|
|
|
68
68
|
VALUE obj;
|
|
69
69
|
|
|
70
70
|
obj = NewX509Ext(cX509Ext);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
new = X509_EXTENSION_dup(ext);
|
|
75
|
-
}
|
|
76
|
-
if (!new) {
|
|
77
|
-
ossl_raise(eX509ExtError, NULL);
|
|
78
|
-
}
|
|
71
|
+
new = X509_EXTENSION_dup(ext);
|
|
72
|
+
if (!new)
|
|
73
|
+
ossl_raise(eX509ExtError, "X509_EXTENSION_dup");
|
|
79
74
|
SetX509Ext(obj, new);
|
|
80
75
|
|
|
81
76
|
return obj;
|
|
@@ -106,7 +101,7 @@ ossl_x509extfactory_free(void *ctx)
|
|
|
106
101
|
static const rb_data_type_t ossl_x509extfactory_type = {
|
|
107
102
|
"OpenSSL/X509/EXTENSION/Factory",
|
|
108
103
|
{
|
|
109
|
-
|
|
104
|
+
0, ossl_x509extfactory_free,
|
|
110
105
|
},
|
|
111
106
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
112
107
|
};
|
|
@@ -180,15 +175,15 @@ ossl_x509extfactory_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
180
175
|
/*GetX509ExtFactory(self, ctx);*/
|
|
181
176
|
|
|
182
177
|
rb_scan_args(argc, argv, "04",
|
|
183
|
-
|
|
178
|
+
&issuer_cert, &subject_cert, &subject_req, &crl);
|
|
184
179
|
if (!NIL_P(issuer_cert))
|
|
185
|
-
|
|
180
|
+
ossl_x509extfactory_set_issuer_cert(self, issuer_cert);
|
|
186
181
|
if (!NIL_P(subject_cert))
|
|
187
|
-
|
|
182
|
+
ossl_x509extfactory_set_subject_cert(self, subject_cert);
|
|
188
183
|
if (!NIL_P(subject_req))
|
|
189
|
-
|
|
184
|
+
ossl_x509extfactory_set_subject_req(self, subject_req);
|
|
190
185
|
if (!NIL_P(crl))
|
|
191
|
-
|
|
186
|
+
ossl_x509extfactory_set_crl(self, crl);
|
|
192
187
|
|
|
193
188
|
return self;
|
|
194
189
|
}
|
|
@@ -218,7 +213,7 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
|
|
|
218
213
|
oid_cstr = StringValueCStr(oid);
|
|
219
214
|
nid = OBJ_ln2nid(oid_cstr);
|
|
220
215
|
if (nid != NID_undef)
|
|
221
|
-
|
|
216
|
+
oid_cstr = OBJ_nid2sn(nid);
|
|
222
217
|
|
|
223
218
|
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
|
|
224
219
|
rb_str_append(valstr, value);
|
|
@@ -230,14 +225,10 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
|
|
|
230
225
|
conf = NIL_P(rconf) ? NULL : GetConfig(rconf);
|
|
231
226
|
X509V3_set_nconf(ctx, conf);
|
|
232
227
|
|
|
233
|
-
#if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_IS_LIBRESSL
|
|
234
228
|
ext = X509V3_EXT_nconf(conf, ctx, oid_cstr, RSTRING_PTR(valstr));
|
|
235
|
-
#else
|
|
236
|
-
ext = X509V3_EXT_nconf(conf, ctx, (char *)oid_cstr, RSTRING_PTR(valstr));
|
|
237
|
-
#endif
|
|
238
229
|
X509V3_set_ctx_nodb(ctx);
|
|
239
230
|
if (!ext){
|
|
240
|
-
|
|
231
|
+
ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr);
|
|
241
232
|
}
|
|
242
233
|
SetX509Ext(obj, ext);
|
|
243
234
|
|
|
@@ -255,7 +246,7 @@ ossl_x509ext_alloc(VALUE klass)
|
|
|
255
246
|
|
|
256
247
|
obj = NewX509Ext(klass);
|
|
257
248
|
if(!(ext = X509_EXTENSION_new())){
|
|
258
|
-
|
|
249
|
+
ossl_raise(eX509ExtError, NULL);
|
|
259
250
|
}
|
|
260
251
|
SetX509Ext(obj, ext);
|
|
261
252
|
|
|
@@ -283,14 +274,14 @@ ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
283
274
|
|
|
284
275
|
GetX509Ext(self, ext);
|
|
285
276
|
if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
277
|
+
oid = ossl_to_der_if_possible(oid);
|
|
278
|
+
StringValue(oid);
|
|
279
|
+
p = (unsigned char *)RSTRING_PTR(oid);
|
|
280
|
+
x = d2i_X509_EXTENSION(&ext, &p, RSTRING_LEN(oid));
|
|
281
|
+
DATA_PTR(self) = ext;
|
|
282
|
+
if(!x)
|
|
283
|
+
ossl_raise(eX509ExtError, NULL);
|
|
284
|
+
return self;
|
|
294
285
|
}
|
|
295
286
|
rb_funcall(self, rb_intern("oid="), 1, oid);
|
|
296
287
|
rb_funcall(self, rb_intern("value="), 1, value);
|
|
@@ -299,6 +290,7 @@ ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
299
290
|
return self;
|
|
300
291
|
}
|
|
301
292
|
|
|
293
|
+
/* :nodoc: */
|
|
302
294
|
static VALUE
|
|
303
295
|
ossl_x509ext_initialize_copy(VALUE self, VALUE other)
|
|
304
296
|
{
|
|
@@ -310,7 +302,7 @@ ossl_x509ext_initialize_copy(VALUE self, VALUE other)
|
|
|
310
302
|
|
|
311
303
|
ext_new = X509_EXTENSION_dup(ext_other);
|
|
312
304
|
if (!ext_new)
|
|
313
|
-
|
|
305
|
+
ossl_raise(eX509ExtError, "X509_EXTENSION_dup");
|
|
314
306
|
|
|
315
307
|
SetX509Ext(self, ext_new);
|
|
316
308
|
X509_EXTENSION_free(ext);
|
|
@@ -327,10 +319,10 @@ ossl_x509ext_set_oid(VALUE self, VALUE oid)
|
|
|
327
319
|
GetX509Ext(self, ext);
|
|
328
320
|
obj = OBJ_txt2obj(StringValueCStr(oid), 0);
|
|
329
321
|
if (!obj)
|
|
330
|
-
|
|
322
|
+
ossl_raise(eX509ExtError, "OBJ_txt2obj");
|
|
331
323
|
if (!X509_EXTENSION_set_object(ext, obj)) {
|
|
332
|
-
|
|
333
|
-
|
|
324
|
+
ASN1_OBJECT_free(obj);
|
|
325
|
+
ossl_raise(eX509ExtError, "X509_EXTENSION_set_object");
|
|
334
326
|
}
|
|
335
327
|
ASN1_OBJECT_free(obj);
|
|
336
328
|
|
|
@@ -349,8 +341,8 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
|
|
|
349
341
|
asn1s = X509_EXTENSION_get_data(ext);
|
|
350
342
|
|
|
351
343
|
if (!ASN1_OCTET_STRING_set(asn1s, (unsigned char *)RSTRING_PTR(data),
|
|
352
|
-
|
|
353
|
-
|
|
344
|
+
RSTRING_LENINT(data))) {
|
|
345
|
+
ossl_raise(eX509ExtError, "ASN1_OCTET_STRING_set");
|
|
354
346
|
}
|
|
355
347
|
|
|
356
348
|
return data;
|
|
@@ -367,27 +359,20 @@ ossl_x509ext_set_critical(VALUE self, VALUE flag)
|
|
|
367
359
|
return flag;
|
|
368
360
|
}
|
|
369
361
|
|
|
362
|
+
/*
|
|
363
|
+
* call-seq:
|
|
364
|
+
* ext.oid -> string
|
|
365
|
+
*
|
|
366
|
+
* Returns the OID of the extension. Returns the short name or the dotted
|
|
367
|
+
* decimal notation.
|
|
368
|
+
*/
|
|
370
369
|
static VALUE
|
|
371
370
|
ossl_x509ext_get_oid(VALUE obj)
|
|
372
371
|
{
|
|
373
372
|
X509_EXTENSION *ext;
|
|
374
|
-
ASN1_OBJECT *extobj;
|
|
375
|
-
BIO *out;
|
|
376
|
-
VALUE ret;
|
|
377
|
-
int nid;
|
|
378
373
|
|
|
379
374
|
GetX509Ext(obj, ext);
|
|
380
|
-
|
|
381
|
-
if ((nid = OBJ_obj2nid(extobj)) != NID_undef)
|
|
382
|
-
ret = rb_str_new2(OBJ_nid2sn(nid));
|
|
383
|
-
else{
|
|
384
|
-
if (!(out = BIO_new(BIO_s_mem())))
|
|
385
|
-
ossl_raise(eX509ExtError, NULL);
|
|
386
|
-
i2a_ASN1_OBJECT(out, extobj);
|
|
387
|
-
ret = ossl_membio2str(out);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return ret;
|
|
375
|
+
return ossl_asn1obj_to_string(X509_EXTENSION_get_object(ext));
|
|
391
376
|
}
|
|
392
377
|
|
|
393
378
|
static VALUE
|
|
@@ -399,9 +384,9 @@ ossl_x509ext_get_value(VALUE obj)
|
|
|
399
384
|
|
|
400
385
|
GetX509Ext(obj, ext);
|
|
401
386
|
if (!(out = BIO_new(BIO_s_mem())))
|
|
402
|
-
|
|
387
|
+
ossl_raise(eX509ExtError, NULL);
|
|
403
388
|
if (!X509V3_EXT_print(out, ext, 0, 0))
|
|
404
|
-
|
|
389
|
+
ASN1_STRING_print(out, (ASN1_STRING *)X509_EXTENSION_get_data(ext));
|
|
405
390
|
ret = ossl_membio2str(out);
|
|
406
391
|
|
|
407
392
|
return ret;
|
|
@@ -415,9 +400,9 @@ ossl_x509ext_get_value_der(VALUE obj)
|
|
|
415
400
|
|
|
416
401
|
GetX509Ext(obj, ext);
|
|
417
402
|
if ((value = X509_EXTENSION_get_data(ext)) == NULL)
|
|
418
|
-
|
|
403
|
+
ossl_raise(eX509ExtError, NULL);
|
|
419
404
|
|
|
420
|
-
return
|
|
405
|
+
return asn1str_to_str(value);
|
|
421
406
|
}
|
|
422
407
|
|
|
423
408
|
static VALUE
|
|
@@ -439,11 +424,11 @@ ossl_x509ext_to_der(VALUE obj)
|
|
|
439
424
|
|
|
440
425
|
GetX509Ext(obj, ext);
|
|
441
426
|
if((len = i2d_X509_EXTENSION(ext, NULL)) <= 0)
|
|
442
|
-
|
|
427
|
+
ossl_raise(eX509ExtError, NULL);
|
|
443
428
|
str = rb_str_new(0, len);
|
|
444
429
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
445
430
|
if(i2d_X509_EXTENSION(ext, &p) < 0)
|
|
446
|
-
|
|
431
|
+
ossl_raise(eX509ExtError, NULL);
|
|
447
432
|
ossl_str_adjust(str, p);
|
|
448
433
|
|
|
449
434
|
return str;
|
|
@@ -456,12 +441,6 @@ void
|
|
|
456
441
|
Init_ossl_x509ext(void)
|
|
457
442
|
{
|
|
458
443
|
#undef rb_intern
|
|
459
|
-
#if 0
|
|
460
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
461
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
462
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
463
|
-
#endif
|
|
464
|
-
|
|
465
444
|
eX509ExtError = rb_define_class_under(mX509, "ExtensionError", eOSSLError);
|
|
466
445
|
|
|
467
446
|
cX509ExtFactory = rb_define_class_under(mX509, "ExtensionFactory", rb_cObject);
|