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