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_x509name.c
CHANGED
|
@@ -13,21 +13,21 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509name_type, 0)
|
|
14
14
|
#define SetX509Name(obj, name) do { \
|
|
15
15
|
if (!(name)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (name); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509Name(obj, name) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_NAME, &ossl_x509name_type, (name)); \
|
|
22
22
|
if (!(name)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
27
27
|
#define OBJECT_TYPE_TEMPLATE \
|
|
28
|
-
|
|
28
|
+
rb_const_get(cX509Name, rb_intern("OBJECT_TYPE_TEMPLATE"))
|
|
29
29
|
#define DEFAULT_OBJECT_TYPE \
|
|
30
|
-
|
|
30
|
+
rb_const_get(cX509Name, rb_intern("DEFAULT_OBJECT_TYPE"))
|
|
31
31
|
|
|
32
32
|
/*
|
|
33
33
|
* Classes
|
|
@@ -44,7 +44,7 @@ ossl_x509name_free(void *ptr)
|
|
|
44
44
|
static const rb_data_type_t ossl_x509name_type = {
|
|
45
45
|
"OpenSSL/X509/NAME",
|
|
46
46
|
{
|
|
47
|
-
|
|
47
|
+
0, ossl_x509name_free,
|
|
48
48
|
},
|
|
49
49
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
50
50
|
};
|
|
@@ -59,15 +59,10 @@ ossl_x509name_new(const X509_NAME *name)
|
|
|
59
59
|
VALUE obj;
|
|
60
60
|
|
|
61
61
|
obj = NewX509Name(cX509Name);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
new = X509_NAME_dup((X509_NAME *)name);
|
|
67
|
-
}
|
|
68
|
-
if (!new) {
|
|
69
|
-
ossl_raise(eX509NameError, NULL);
|
|
70
|
-
}
|
|
62
|
+
/* OpenSSL 1.1.1 takes a non-const pointer */
|
|
63
|
+
new = X509_NAME_dup((X509_NAME *)name);
|
|
64
|
+
if (!new)
|
|
65
|
+
ossl_raise(eX509NameError, "X509_NAME_dup");
|
|
71
66
|
SetX509Name(obj, new);
|
|
72
67
|
|
|
73
68
|
return obj;
|
|
@@ -94,7 +89,7 @@ ossl_x509name_alloc(VALUE klass)
|
|
|
94
89
|
|
|
95
90
|
obj = NewX509Name(klass);
|
|
96
91
|
if (!(name = X509_NAME_new())) {
|
|
97
|
-
|
|
92
|
+
ossl_raise(eX509NameError, NULL);
|
|
98
93
|
}
|
|
99
94
|
SetX509Name(obj, name);
|
|
100
95
|
|
|
@@ -151,33 +146,34 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
151
146
|
|
|
152
147
|
GetX509Name(self, name);
|
|
153
148
|
if (rb_scan_args(argc, argv, "02", &arg, &template) == 0) {
|
|
154
|
-
|
|
149
|
+
return self;
|
|
155
150
|
}
|
|
156
151
|
else {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
152
|
+
VALUE tmp = rb_check_array_type(arg);
|
|
153
|
+
if (!NIL_P(tmp)) {
|
|
154
|
+
VALUE args;
|
|
155
|
+
if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
|
|
156
|
+
args = rb_ary_new3(2, self, template);
|
|
157
|
+
rb_block_call(tmp, rb_intern("each"), 0, 0, ossl_x509name_init_i, args);
|
|
158
|
+
}
|
|
159
|
+
else{
|
|
160
|
+
const unsigned char *p;
|
|
161
|
+
VALUE str = ossl_to_der_if_possible(arg);
|
|
162
|
+
X509_NAME *x;
|
|
163
|
+
StringValue(str);
|
|
164
|
+
p = (unsigned char *)RSTRING_PTR(str);
|
|
165
|
+
x = d2i_X509_NAME(&name, &p, RSTRING_LEN(str));
|
|
166
|
+
DATA_PTR(self) = name;
|
|
167
|
+
if(!x){
|
|
168
|
+
ossl_raise(eX509NameError, NULL);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
176
171
|
}
|
|
177
172
|
|
|
178
173
|
return self;
|
|
179
174
|
}
|
|
180
175
|
|
|
176
|
+
/* :nodoc: */
|
|
181
177
|
static VALUE
|
|
182
178
|
ossl_x509name_initialize_copy(VALUE self, VALUE other)
|
|
183
179
|
{
|
|
@@ -189,7 +185,7 @@ ossl_x509name_initialize_copy(VALUE self, VALUE other)
|
|
|
189
185
|
|
|
190
186
|
name_new = X509_NAME_dup(name_other);
|
|
191
187
|
if (!name_new)
|
|
192
|
-
|
|
188
|
+
ossl_raise(eX509NameError, "X509_NAME_dup");
|
|
193
189
|
|
|
194
190
|
SetX509Name(self, name_new);
|
|
195
191
|
X509_NAME_free(name);
|
|
@@ -226,8 +222,8 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
|
|
|
226
222
|
int loc = -1, set = 0;
|
|
227
223
|
|
|
228
224
|
if (!kwargs_ids[0]) {
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
kwargs_ids[0] = rb_intern_const("loc");
|
|
226
|
+
kwargs_ids[1] = rb_intern_const("set");
|
|
231
227
|
}
|
|
232
228
|
rb_scan_args(argc, argv, "21:", &oid, &value, &type, &opts);
|
|
233
229
|
rb_get_kwargs(opts, kwargs_ids, 0, 2, kwargs);
|
|
@@ -235,14 +231,14 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
|
|
|
235
231
|
StringValue(value);
|
|
236
232
|
if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
|
|
237
233
|
if (kwargs[0] != Qundef)
|
|
238
|
-
|
|
234
|
+
loc = NUM2INT(kwargs[0]);
|
|
239
235
|
if (kwargs[1] != Qundef)
|
|
240
|
-
|
|
236
|
+
set = NUM2INT(kwargs[1]);
|
|
241
237
|
GetX509Name(self, name);
|
|
242
238
|
if (!X509_NAME_add_entry_by_txt(name, oid_name, NUM2INT(type),
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
(unsigned char *)RSTRING_PTR(value),
|
|
240
|
+
RSTRING_LENINT(value), loc, set))
|
|
241
|
+
ossl_raise(eX509NameError, "X509_NAME_add_entry_by_txt");
|
|
246
242
|
return self;
|
|
247
243
|
}
|
|
248
244
|
|
|
@@ -255,7 +251,7 @@ ossl_x509name_to_s_old(VALUE self)
|
|
|
255
251
|
GetX509Name(self, name);
|
|
256
252
|
buf = X509_NAME_oneline(name, NULL, 0);
|
|
257
253
|
if (!buf)
|
|
258
|
-
|
|
254
|
+
ossl_raise(eX509NameError, "X509_NAME_oneline");
|
|
259
255
|
return ossl_buf2str(buf, rb_long2int(strlen(buf)));
|
|
260
256
|
}
|
|
261
257
|
|
|
@@ -269,11 +265,11 @@ x509name_print(VALUE self, unsigned long iflag)
|
|
|
269
265
|
GetX509Name(self, name);
|
|
270
266
|
out = BIO_new(BIO_s_mem());
|
|
271
267
|
if (!out)
|
|
272
|
-
|
|
268
|
+
ossl_raise(eX509NameError, NULL);
|
|
273
269
|
ret = X509_NAME_print_ex(out, name, 0, iflag);
|
|
274
270
|
if (ret < 0 || (iflag == XN_FLAG_COMPAT && ret == 0)) {
|
|
275
|
-
|
|
276
|
-
|
|
271
|
+
BIO_free(out);
|
|
272
|
+
ossl_raise(eX509NameError, "X509_NAME_print_ex");
|
|
277
273
|
}
|
|
278
274
|
return ossl_membio2str(out);
|
|
279
275
|
}
|
|
@@ -307,9 +303,9 @@ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
|
|
|
307
303
|
rb_check_arity(argc, 0, 1);
|
|
308
304
|
/* name.to_s(nil) was allowed */
|
|
309
305
|
if (!argc || NIL_P(argv[0]))
|
|
310
|
-
|
|
306
|
+
return ossl_x509name_to_s_old(self);
|
|
311
307
|
else
|
|
312
|
-
|
|
308
|
+
return x509name_print(self, NUM2ULONG(argv[0]));
|
|
313
309
|
}
|
|
314
310
|
|
|
315
311
|
/*
|
|
@@ -332,7 +328,7 @@ static VALUE
|
|
|
332
328
|
ossl_x509name_inspect(VALUE self)
|
|
333
329
|
{
|
|
334
330
|
return rb_enc_sprintf(rb_utf8_encoding(), "#<%"PRIsVALUE" %"PRIsVALUE">",
|
|
335
|
-
|
|
331
|
+
rb_obj_class(self), ossl_x509name_to_utf8(self));
|
|
336
332
|
}
|
|
337
333
|
|
|
338
334
|
/*
|
|
@@ -346,39 +342,22 @@ static VALUE
|
|
|
346
342
|
ossl_x509name_to_a(VALUE self)
|
|
347
343
|
{
|
|
348
344
|
X509_NAME *name;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
char long_name[512];
|
|
352
|
-
const char *short_name;
|
|
353
|
-
VALUE ary, vname, ret;
|
|
354
|
-
ASN1_STRING *value;
|
|
345
|
+
int entries;
|
|
346
|
+
VALUE ret;
|
|
355
347
|
|
|
356
348
|
GetX509Name(self, name);
|
|
357
349
|
entries = X509_NAME_entry_count(name);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
ossl_raise(eX509NameError, NULL);
|
|
370
|
-
}
|
|
371
|
-
nid = OBJ_ln2nid(long_name);
|
|
372
|
-
if (nid == NID_undef) {
|
|
373
|
-
vname = rb_str_new2((const char *) &long_name);
|
|
374
|
-
} else {
|
|
375
|
-
short_name = OBJ_nid2sn(nid);
|
|
376
|
-
vname = rb_str_new2(short_name); /*do not free*/
|
|
377
|
-
}
|
|
378
|
-
value = (ASN1_STRING *)X509_NAME_ENTRY_get_data(entry);
|
|
379
|
-
ary = rb_ary_new3(3, vname, asn1str_to_str(value),
|
|
380
|
-
INT2NUM(ASN1_STRING_type(value)));
|
|
381
|
-
rb_ary_push(ret, ary);
|
|
350
|
+
ret = rb_ary_new_capa(entries);
|
|
351
|
+
for (int i = 0; i < entries; i++) {
|
|
352
|
+
const X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
|
|
353
|
+
if (!entry)
|
|
354
|
+
ossl_raise(eX509NameError, "X509_NAME_get_entry");
|
|
355
|
+
const ASN1_OBJECT *obj = X509_NAME_ENTRY_get_object(entry);
|
|
356
|
+
VALUE vname = ossl_asn1obj_to_string(obj);
|
|
357
|
+
const ASN1_STRING *data = X509_NAME_ENTRY_get_data(entry);
|
|
358
|
+
VALUE vdata = asn1str_to_str(data);
|
|
359
|
+
VALUE type = INT2NUM(ASN1_STRING_type(data));
|
|
360
|
+
rb_ary_push(ret, rb_ary_new_from_args(3, vname, vdata, type));
|
|
382
361
|
}
|
|
383
362
|
return ret;
|
|
384
363
|
}
|
|
@@ -409,7 +388,7 @@ ossl_x509name_cmp(VALUE self, VALUE other)
|
|
|
409
388
|
int result;
|
|
410
389
|
|
|
411
390
|
if (!rb_obj_is_kind_of(other, cX509Name))
|
|
412
|
-
|
|
391
|
+
return Qnil;
|
|
413
392
|
|
|
414
393
|
result = ossl_x509name_cmp0(self, other);
|
|
415
394
|
if (result < 0) return INT2FIX(-1);
|
|
@@ -428,7 +407,7 @@ static VALUE
|
|
|
428
407
|
ossl_x509name_eql(VALUE self, VALUE other)
|
|
429
408
|
{
|
|
430
409
|
if (!rb_obj_is_kind_of(other, cX509Name))
|
|
431
|
-
|
|
410
|
+
return Qfalse;
|
|
432
411
|
|
|
433
412
|
return ossl_x509name_cmp0(self, other) == 0 ? Qtrue : Qfalse;
|
|
434
413
|
}
|
|
@@ -488,11 +467,11 @@ ossl_x509name_to_der(VALUE self)
|
|
|
488
467
|
|
|
489
468
|
GetX509Name(self, name);
|
|
490
469
|
if((len = i2d_X509_NAME(name, NULL)) <= 0)
|
|
491
|
-
|
|
470
|
+
ossl_raise(eX509NameError, NULL);
|
|
492
471
|
str = rb_str_new(0, len);
|
|
493
472
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
494
473
|
if(i2d_X509_NAME(name, &p) <= 0)
|
|
495
|
-
|
|
474
|
+
ossl_raise(eX509NameError, NULL);
|
|
496
475
|
ossl_str_adjust(str, p);
|
|
497
476
|
|
|
498
477
|
return str;
|
|
@@ -518,12 +497,6 @@ Init_ossl_x509name(void)
|
|
|
518
497
|
#undef rb_intern
|
|
519
498
|
VALUE utf8str, ptrstr, ia5str, hash;
|
|
520
499
|
|
|
521
|
-
#if 0
|
|
522
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
523
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
524
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
525
|
-
#endif
|
|
526
|
-
|
|
527
500
|
id_aref = rb_intern("[]");
|
|
528
501
|
eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
|
|
529
502
|
cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
|
|
@@ -562,6 +535,7 @@ Init_ossl_x509name(void)
|
|
|
562
535
|
rb_hash_aset(hash, rb_str_new2("DC"), ia5str);
|
|
563
536
|
rb_hash_aset(hash, rb_str_new2("domainComponent"), ia5str);
|
|
564
537
|
rb_hash_aset(hash, rb_str_new2("emailAddress"), ia5str);
|
|
538
|
+
rb_obj_freeze(hash);
|
|
565
539
|
|
|
566
540
|
/*
|
|
567
541
|
* The default object type template for name entries.
|
data/ext/openssl/ossl_x509req.c
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509req_type, 0)
|
|
14
14
|
#define SetX509Req(obj, req) do { \
|
|
15
15
|
if (!(req)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (req); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509Req(obj, req) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_REQ, &ossl_x509req_type, (req)); \
|
|
22
22
|
if (!(req)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ ossl_x509req_free(void *ptr)
|
|
|
39
39
|
static const rb_data_type_t ossl_x509req_type = {
|
|
40
40
|
"OpenSSL/X509/REQ",
|
|
41
41
|
{
|
|
42
|
-
|
|
42
|
+
0, ossl_x509req_free,
|
|
43
43
|
},
|
|
44
44
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
45
45
|
};
|
|
@@ -68,7 +68,7 @@ ossl_x509req_alloc(VALUE klass)
|
|
|
68
68
|
|
|
69
69
|
obj = NewX509Req(klass);
|
|
70
70
|
if (!(req = X509_REQ_new())) {
|
|
71
|
-
|
|
71
|
+
ossl_raise(eX509ReqError, NULL);
|
|
72
72
|
}
|
|
73
73
|
SetX509Req(obj, req);
|
|
74
74
|
|
|
@@ -84,7 +84,7 @@ ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
84
84
|
|
|
85
85
|
rb_check_frozen(self);
|
|
86
86
|
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
|
|
87
|
-
|
|
87
|
+
return self;
|
|
88
88
|
}
|
|
89
89
|
arg = ossl_to_der_if_possible(arg);
|
|
90
90
|
in = ossl_obj2bio(&arg);
|
|
@@ -103,6 +103,7 @@ ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
103
103
|
return self;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/* :nodoc: */
|
|
106
107
|
static VALUE
|
|
107
108
|
ossl_x509req_copy(VALUE self, VALUE other)
|
|
108
109
|
{
|
|
@@ -113,7 +114,7 @@ ossl_x509req_copy(VALUE self, VALUE other)
|
|
|
113
114
|
GetX509Req(self, a);
|
|
114
115
|
GetX509Req(other, b);
|
|
115
116
|
if (!(req = X509_REQ_dup(b))) {
|
|
116
|
-
|
|
117
|
+
ossl_raise(eX509ReqError, NULL);
|
|
117
118
|
}
|
|
118
119
|
X509_REQ_free(a);
|
|
119
120
|
DATA_PTR(self) = req;
|
|
@@ -129,11 +130,11 @@ ossl_x509req_to_pem(VALUE self)
|
|
|
129
130
|
|
|
130
131
|
GetX509Req(self, req);
|
|
131
132
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
132
|
-
|
|
133
|
+
ossl_raise(eX509ReqError, NULL);
|
|
133
134
|
}
|
|
134
135
|
if (!PEM_write_bio_X509_REQ(out, req)) {
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
BIO_free(out);
|
|
137
|
+
ossl_raise(eX509ReqError, NULL);
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
return ossl_membio2str(out);
|
|
@@ -149,11 +150,11 @@ ossl_x509req_to_der(VALUE self)
|
|
|
149
150
|
|
|
150
151
|
GetX509Req(self, req);
|
|
151
152
|
if ((len = i2d_X509_REQ(req, NULL)) <= 0)
|
|
152
|
-
|
|
153
|
+
ossl_raise(eX509ReqError, NULL);
|
|
153
154
|
str = rb_str_new(0, len);
|
|
154
155
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
155
156
|
if (i2d_X509_REQ(req, &p) <= 0)
|
|
156
|
-
|
|
157
|
+
ossl_raise(eX509ReqError, NULL);
|
|
157
158
|
ossl_str_adjust(str, p);
|
|
158
159
|
|
|
159
160
|
return str;
|
|
@@ -167,11 +168,11 @@ ossl_x509req_to_text(VALUE self)
|
|
|
167
168
|
|
|
168
169
|
GetX509Req(self, req);
|
|
169
170
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
170
|
-
|
|
171
|
+
ossl_raise(eX509ReqError, NULL);
|
|
171
172
|
}
|
|
172
173
|
if (!X509_REQ_print(out, req)) {
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
BIO_free(out);
|
|
175
|
+
ossl_raise(eX509ReqError, NULL);
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
return ossl_membio2str(out);
|
|
@@ -190,7 +191,7 @@ ossl_x509req_to_x509(VALUE self, VALUE days, VALUE key)
|
|
|
190
191
|
GetX509Req(self, req);
|
|
191
192
|
...
|
|
192
193
|
if (!(x509 = X509_REQ_to_X509(req, d, pkey))) {
|
|
193
|
-
|
|
194
|
+
ossl_raise(eX509ReqError, NULL);
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
return ossl_x509_new(x509);
|
|
@@ -216,11 +217,11 @@ ossl_x509req_set_version(VALUE self, VALUE version)
|
|
|
216
217
|
long ver;
|
|
217
218
|
|
|
218
219
|
if ((ver = NUM2LONG(version)) < 0) {
|
|
219
|
-
|
|
220
|
+
ossl_raise(eX509ReqError, "version must be >= 0!");
|
|
220
221
|
}
|
|
221
222
|
GetX509Req(self, req);
|
|
222
223
|
if (!X509_REQ_set_version(req, ver)) {
|
|
223
|
-
|
|
224
|
+
ossl_raise(eX509ReqError, "X509_REQ_set_version");
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
return version;
|
|
@@ -234,7 +235,7 @@ ossl_x509req_get_subject(VALUE self)
|
|
|
234
235
|
|
|
235
236
|
GetX509Req(self, req);
|
|
236
237
|
if (!(name = X509_REQ_get_subject_name(req))) { /* NO DUP - don't free */
|
|
237
|
-
|
|
238
|
+
ossl_raise(eX509ReqError, NULL);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
return ossl_x509name_new(name);
|
|
@@ -248,31 +249,32 @@ ossl_x509req_set_subject(VALUE self, VALUE subject)
|
|
|
248
249
|
GetX509Req(self, req);
|
|
249
250
|
/* DUPs name */
|
|
250
251
|
if (!X509_REQ_set_subject_name(req, GetX509NamePtr(subject))) {
|
|
251
|
-
|
|
252
|
+
ossl_raise(eX509ReqError, NULL);
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
return subject;
|
|
255
256
|
}
|
|
256
257
|
|
|
258
|
+
/*
|
|
259
|
+
* call-seq:
|
|
260
|
+
* req.signature_algorithm -> string
|
|
261
|
+
*
|
|
262
|
+
* Returns the signature algorithm used to sign this request.
|
|
263
|
+
*
|
|
264
|
+
* Returns the long name of the signature algorithm, or the dotted decimal
|
|
265
|
+
* notation if \OpenSSL does not define a long name for it.
|
|
266
|
+
*/
|
|
257
267
|
static VALUE
|
|
258
268
|
ossl_x509req_get_signature_algorithm(VALUE self)
|
|
259
269
|
{
|
|
260
270
|
X509_REQ *req;
|
|
261
271
|
const X509_ALGOR *alg;
|
|
262
|
-
|
|
272
|
+
const ASN1_OBJECT *obj;
|
|
263
273
|
|
|
264
274
|
GetX509Req(self, req);
|
|
265
|
-
|
|
266
|
-
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
267
|
-
ossl_raise(eX509ReqError, NULL);
|
|
268
|
-
}
|
|
269
275
|
X509_REQ_get0_signature(req, NULL, &alg);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
ossl_raise(eX509ReqError, NULL);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return ossl_membio2str(out);
|
|
276
|
+
X509_ALGOR_get0(&obj, NULL, NULL, alg);
|
|
277
|
+
return ossl_asn1obj_to_string_long_name(obj);
|
|
276
278
|
}
|
|
277
279
|
|
|
278
280
|
static VALUE
|
|
@@ -283,10 +285,10 @@ ossl_x509req_get_public_key(VALUE self)
|
|
|
283
285
|
|
|
284
286
|
GetX509Req(self, req);
|
|
285
287
|
if (!(pkey = X509_REQ_get_pubkey(req))) { /* adds reference */
|
|
286
|
-
|
|
288
|
+
ossl_raise(eX509ReqError, NULL);
|
|
287
289
|
}
|
|
288
290
|
|
|
289
|
-
return
|
|
291
|
+
return ossl_pkey_wrap(pkey);
|
|
290
292
|
}
|
|
291
293
|
|
|
292
294
|
static VALUE
|
|
@@ -299,7 +301,7 @@ ossl_x509req_set_public_key(VALUE self, VALUE key)
|
|
|
299
301
|
pkey = GetPKeyPtr(key);
|
|
300
302
|
ossl_pkey_check_public_key(pkey);
|
|
301
303
|
if (!X509_REQ_set_pubkey(req, pkey))
|
|
302
|
-
|
|
304
|
+
ossl_raise(eX509ReqError, "X509_REQ_set_pubkey");
|
|
303
305
|
return key;
|
|
304
306
|
}
|
|
305
307
|
|
|
@@ -309,17 +311,14 @@ ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
|
|
|
309
311
|
X509_REQ *req;
|
|
310
312
|
EVP_PKEY *pkey;
|
|
311
313
|
const EVP_MD *md;
|
|
314
|
+
VALUE md_holder;
|
|
312
315
|
|
|
313
316
|
GetX509Req(self, req);
|
|
314
317
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
if (!X509_REQ_sign(req, pkey, md)) {
|
|
321
|
-
ossl_raise(eX509ReqError, NULL);
|
|
322
|
-
}
|
|
318
|
+
/* NULL needed for some key types, e.g. Ed25519 */
|
|
319
|
+
md = NIL_P(digest) ? NULL : ossl_evp_md_fetch(digest, &md_holder);
|
|
320
|
+
if (!X509_REQ_sign(req, pkey, md))
|
|
321
|
+
ossl_raise(eX509ReqError, "X509_REQ_sign");
|
|
323
322
|
|
|
324
323
|
return self;
|
|
325
324
|
}
|
|
@@ -338,12 +337,12 @@ ossl_x509req_verify(VALUE self, VALUE key)
|
|
|
338
337
|
ossl_pkey_check_public_key(pkey);
|
|
339
338
|
switch (X509_REQ_verify(req, pkey)) {
|
|
340
339
|
case 1:
|
|
341
|
-
|
|
340
|
+
return Qtrue;
|
|
342
341
|
case 0:
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
ossl_clear_error();
|
|
343
|
+
return Qfalse;
|
|
345
344
|
default:
|
|
346
|
-
|
|
345
|
+
ossl_raise(eX509ReqError, NULL);
|
|
347
346
|
}
|
|
348
347
|
}
|
|
349
348
|
|
|
@@ -359,13 +358,13 @@ ossl_x509req_get_attributes(VALUE self)
|
|
|
359
358
|
|
|
360
359
|
count = X509_REQ_get_attr_count(req);
|
|
361
360
|
if (count < 0) {
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
OSSL_Debug("count < 0???");
|
|
362
|
+
return rb_ary_new();
|
|
364
363
|
}
|
|
365
364
|
ary = rb_ary_new2(count);
|
|
366
365
|
for (i=0; i<count; i++) {
|
|
367
|
-
|
|
368
|
-
|
|
366
|
+
attr = X509_REQ_get_attr(req, i);
|
|
367
|
+
rb_ary_push(ary, ossl_x509attr_new(attr));
|
|
369
368
|
}
|
|
370
369
|
|
|
371
370
|
return ary;
|
|
@@ -381,17 +380,17 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
|
|
|
381
380
|
|
|
382
381
|
Check_Type(ary, T_ARRAY);
|
|
383
382
|
for (i=0;i<RARRAY_LEN(ary); i++) {
|
|
384
|
-
|
|
383
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Attr);
|
|
385
384
|
}
|
|
386
385
|
GetX509Req(self, req);
|
|
387
386
|
for (i = X509_REQ_get_attr_count(req); i > 0; i--)
|
|
388
387
|
X509_ATTRIBUTE_free(X509_REQ_delete_attr(req, 0));
|
|
389
388
|
for (i=0;i<RARRAY_LEN(ary); i++) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
389
|
+
item = RARRAY_AREF(ary, i);
|
|
390
|
+
attr = GetX509AttrPtr(item);
|
|
391
|
+
if (!X509_REQ_add1_attr(req, attr)) {
|
|
392
|
+
ossl_raise(eX509ReqError, "X509_REQ_add1_attr");
|
|
393
|
+
}
|
|
395
394
|
}
|
|
396
395
|
return ary;
|
|
397
396
|
}
|
|
@@ -403,7 +402,7 @@ ossl_x509req_add_attribute(VALUE self, VALUE attr)
|
|
|
403
402
|
|
|
404
403
|
GetX509Req(self, req);
|
|
405
404
|
if (!X509_REQ_add1_attr(req, GetX509AttrPtr(attr))) {
|
|
406
|
-
|
|
405
|
+
ossl_raise(eX509ReqError, NULL);
|
|
407
406
|
}
|
|
408
407
|
|
|
409
408
|
return attr;
|
|
@@ -415,12 +414,6 @@ ossl_x509req_add_attribute(VALUE self, VALUE attr)
|
|
|
415
414
|
void
|
|
416
415
|
Init_ossl_x509req(void)
|
|
417
416
|
{
|
|
418
|
-
#if 0
|
|
419
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
420
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
421
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
422
|
-
#endif
|
|
423
|
-
|
|
424
417
|
eX509ReqError = rb_define_class_under(mX509, "RequestError", eOSSLError);
|
|
425
418
|
|
|
426
419
|
cX509Req = rb_define_class_under(mX509, "Request", rb_cObject);
|