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