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_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,14 +59,9 @@ ossl_x509name_new(X509_NAME *name)
|
|
|
59
59
|
VALUE obj;
|
|
60
60
|
|
|
61
61
|
obj = NewX509Name(cX509Name);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
new = X509_NAME_dup(name);
|
|
66
|
-
}
|
|
67
|
-
if (!new) {
|
|
68
|
-
ossl_raise(eX509NameError, NULL);
|
|
69
|
-
}
|
|
62
|
+
new = X509_NAME_dup(name);
|
|
63
|
+
if (!new)
|
|
64
|
+
ossl_raise(eX509NameError, "X509_NAME_dup");
|
|
70
65
|
SetX509Name(obj, new);
|
|
71
66
|
|
|
72
67
|
return obj;
|
|
@@ -93,7 +88,7 @@ ossl_x509name_alloc(VALUE klass)
|
|
|
93
88
|
|
|
94
89
|
obj = NewX509Name(klass);
|
|
95
90
|
if (!(name = X509_NAME_new())) {
|
|
96
|
-
|
|
91
|
+
ossl_raise(eX509NameError, NULL);
|
|
97
92
|
}
|
|
98
93
|
SetX509Name(obj, name);
|
|
99
94
|
|
|
@@ -150,33 +145,34 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
150
145
|
|
|
151
146
|
GetX509Name(self, name);
|
|
152
147
|
if (rb_scan_args(argc, argv, "02", &arg, &template) == 0) {
|
|
153
|
-
|
|
148
|
+
return self;
|
|
154
149
|
}
|
|
155
150
|
else {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
151
|
+
VALUE tmp = rb_check_array_type(arg);
|
|
152
|
+
if (!NIL_P(tmp)) {
|
|
153
|
+
VALUE args;
|
|
154
|
+
if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
|
|
155
|
+
args = rb_ary_new3(2, self, template);
|
|
156
|
+
rb_block_call(tmp, rb_intern("each"), 0, 0, ossl_x509name_init_i, args);
|
|
157
|
+
}
|
|
158
|
+
else{
|
|
159
|
+
const unsigned char *p;
|
|
160
|
+
VALUE str = ossl_to_der_if_possible(arg);
|
|
161
|
+
X509_NAME *x;
|
|
162
|
+
StringValue(str);
|
|
163
|
+
p = (unsigned char *)RSTRING_PTR(str);
|
|
164
|
+
x = d2i_X509_NAME(&name, &p, RSTRING_LEN(str));
|
|
165
|
+
DATA_PTR(self) = name;
|
|
166
|
+
if(!x){
|
|
167
|
+
ossl_raise(eX509NameError, NULL);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
return self;
|
|
178
173
|
}
|
|
179
174
|
|
|
175
|
+
/* :nodoc: */
|
|
180
176
|
static VALUE
|
|
181
177
|
ossl_x509name_initialize_copy(VALUE self, VALUE other)
|
|
182
178
|
{
|
|
@@ -188,7 +184,7 @@ ossl_x509name_initialize_copy(VALUE self, VALUE other)
|
|
|
188
184
|
|
|
189
185
|
name_new = X509_NAME_dup(name_other);
|
|
190
186
|
if (!name_new)
|
|
191
|
-
|
|
187
|
+
ossl_raise(eX509NameError, "X509_NAME_dup");
|
|
192
188
|
|
|
193
189
|
SetX509Name(self, name_new);
|
|
194
190
|
X509_NAME_free(name);
|
|
@@ -225,8 +221,8 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
|
|
|
225
221
|
int loc = -1, set = 0;
|
|
226
222
|
|
|
227
223
|
if (!kwargs_ids[0]) {
|
|
228
|
-
|
|
229
|
-
|
|
224
|
+
kwargs_ids[0] = rb_intern_const("loc");
|
|
225
|
+
kwargs_ids[1] = rb_intern_const("set");
|
|
230
226
|
}
|
|
231
227
|
rb_scan_args(argc, argv, "21:", &oid, &value, &type, &opts);
|
|
232
228
|
rb_get_kwargs(opts, kwargs_ids, 0, 2, kwargs);
|
|
@@ -234,14 +230,14 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
|
|
|
234
230
|
StringValue(value);
|
|
235
231
|
if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
|
|
236
232
|
if (kwargs[0] != Qundef)
|
|
237
|
-
|
|
233
|
+
loc = NUM2INT(kwargs[0]);
|
|
238
234
|
if (kwargs[1] != Qundef)
|
|
239
|
-
|
|
235
|
+
set = NUM2INT(kwargs[1]);
|
|
240
236
|
GetX509Name(self, name);
|
|
241
237
|
if (!X509_NAME_add_entry_by_txt(name, oid_name, NUM2INT(type),
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
(unsigned char *)RSTRING_PTR(value),
|
|
239
|
+
RSTRING_LENINT(value), loc, set))
|
|
240
|
+
ossl_raise(eX509NameError, "X509_NAME_add_entry_by_txt");
|
|
245
241
|
return self;
|
|
246
242
|
}
|
|
247
243
|
|
|
@@ -254,7 +250,7 @@ ossl_x509name_to_s_old(VALUE self)
|
|
|
254
250
|
GetX509Name(self, name);
|
|
255
251
|
buf = X509_NAME_oneline(name, NULL, 0);
|
|
256
252
|
if (!buf)
|
|
257
|
-
|
|
253
|
+
ossl_raise(eX509NameError, "X509_NAME_oneline");
|
|
258
254
|
return ossl_buf2str(buf, rb_long2int(strlen(buf)));
|
|
259
255
|
}
|
|
260
256
|
|
|
@@ -268,11 +264,11 @@ x509name_print(VALUE self, unsigned long iflag)
|
|
|
268
264
|
GetX509Name(self, name);
|
|
269
265
|
out = BIO_new(BIO_s_mem());
|
|
270
266
|
if (!out)
|
|
271
|
-
|
|
267
|
+
ossl_raise(eX509NameError, NULL);
|
|
272
268
|
ret = X509_NAME_print_ex(out, name, 0, iflag);
|
|
273
269
|
if (ret < 0 || (iflag == XN_FLAG_COMPAT && ret == 0)) {
|
|
274
|
-
|
|
275
|
-
|
|
270
|
+
BIO_free(out);
|
|
271
|
+
ossl_raise(eX509NameError, "X509_NAME_print_ex");
|
|
276
272
|
}
|
|
277
273
|
return ossl_membio2str(out);
|
|
278
274
|
}
|
|
@@ -306,9 +302,9 @@ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
|
|
|
306
302
|
rb_check_arity(argc, 0, 1);
|
|
307
303
|
/* name.to_s(nil) was allowed */
|
|
308
304
|
if (!argc || NIL_P(argv[0]))
|
|
309
|
-
|
|
305
|
+
return ossl_x509name_to_s_old(self);
|
|
310
306
|
else
|
|
311
|
-
|
|
307
|
+
return x509name_print(self, NUM2ULONG(argv[0]));
|
|
312
308
|
}
|
|
313
309
|
|
|
314
310
|
/*
|
|
@@ -331,7 +327,7 @@ static VALUE
|
|
|
331
327
|
ossl_x509name_inspect(VALUE self)
|
|
332
328
|
{
|
|
333
329
|
return rb_enc_sprintf(rb_utf8_encoding(), "#<%"PRIsVALUE" %"PRIsVALUE">",
|
|
334
|
-
|
|
330
|
+
rb_obj_class(self), ossl_x509name_to_utf8(self));
|
|
335
331
|
}
|
|
336
332
|
|
|
337
333
|
/*
|
|
@@ -345,38 +341,22 @@ static VALUE
|
|
|
345
341
|
ossl_x509name_to_a(VALUE self)
|
|
346
342
|
{
|
|
347
343
|
X509_NAME *name;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
char long_name[512];
|
|
351
|
-
const char *short_name;
|
|
352
|
-
VALUE ary, vname, ret;
|
|
353
|
-
ASN1_STRING *value;
|
|
344
|
+
int entries;
|
|
345
|
+
VALUE ret;
|
|
354
346
|
|
|
355
347
|
GetX509Name(self, name);
|
|
356
348
|
entries = X509_NAME_entry_count(name);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
ossl_raise(eX509NameError, NULL);
|
|
369
|
-
}
|
|
370
|
-
nid = OBJ_ln2nid(long_name);
|
|
371
|
-
if (nid == NID_undef) {
|
|
372
|
-
vname = rb_str_new2((const char *) &long_name);
|
|
373
|
-
} else {
|
|
374
|
-
short_name = OBJ_nid2sn(nid);
|
|
375
|
-
vname = rb_str_new2(short_name); /*do not free*/
|
|
376
|
-
}
|
|
377
|
-
value = X509_NAME_ENTRY_get_data(entry);
|
|
378
|
-
ary = rb_ary_new3(3, vname, asn1str_to_str(value), INT2NUM(value->type));
|
|
379
|
-
rb_ary_push(ret, ary);
|
|
349
|
+
ret = rb_ary_new_capa(entries);
|
|
350
|
+
for (int i = 0; i < entries; i++) {
|
|
351
|
+
const X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
|
|
352
|
+
if (!entry)
|
|
353
|
+
ossl_raise(eX509NameError, "X509_NAME_get_entry");
|
|
354
|
+
const ASN1_OBJECT *obj = X509_NAME_ENTRY_get_object(entry);
|
|
355
|
+
VALUE vname = ossl_asn1obj_to_string(obj);
|
|
356
|
+
const ASN1_STRING *data = X509_NAME_ENTRY_get_data(entry);
|
|
357
|
+
VALUE vdata = asn1str_to_str(data);
|
|
358
|
+
VALUE type = INT2NUM(ASN1_STRING_type(data));
|
|
359
|
+
rb_ary_push(ret, rb_ary_new_from_args(3, vname, vdata, type));
|
|
380
360
|
}
|
|
381
361
|
return ret;
|
|
382
362
|
}
|
|
@@ -407,7 +387,7 @@ ossl_x509name_cmp(VALUE self, VALUE other)
|
|
|
407
387
|
int result;
|
|
408
388
|
|
|
409
389
|
if (!rb_obj_is_kind_of(other, cX509Name))
|
|
410
|
-
|
|
390
|
+
return Qnil;
|
|
411
391
|
|
|
412
392
|
result = ossl_x509name_cmp0(self, other);
|
|
413
393
|
if (result < 0) return INT2FIX(-1);
|
|
@@ -426,7 +406,7 @@ static VALUE
|
|
|
426
406
|
ossl_x509name_eql(VALUE self, VALUE other)
|
|
427
407
|
{
|
|
428
408
|
if (!rb_obj_is_kind_of(other, cX509Name))
|
|
429
|
-
|
|
409
|
+
return Qfalse;
|
|
430
410
|
|
|
431
411
|
return ossl_x509name_cmp0(self, other) == 0 ? Qtrue : Qfalse;
|
|
432
412
|
}
|
|
@@ -486,11 +466,11 @@ ossl_x509name_to_der(VALUE self)
|
|
|
486
466
|
|
|
487
467
|
GetX509Name(self, name);
|
|
488
468
|
if((len = i2d_X509_NAME(name, NULL)) <= 0)
|
|
489
|
-
|
|
469
|
+
ossl_raise(eX509NameError, NULL);
|
|
490
470
|
str = rb_str_new(0, len);
|
|
491
471
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
492
472
|
if(i2d_X509_NAME(name, &p) <= 0)
|
|
493
|
-
|
|
473
|
+
ossl_raise(eX509NameError, NULL);
|
|
494
474
|
ossl_str_adjust(str, p);
|
|
495
475
|
|
|
496
476
|
return str;
|
|
@@ -516,12 +496,6 @@ Init_ossl_x509name(void)
|
|
|
516
496
|
#undef rb_intern
|
|
517
497
|
VALUE utf8str, ptrstr, ia5str, hash;
|
|
518
498
|
|
|
519
|
-
#if 0
|
|
520
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
521
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
522
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
523
|
-
#endif
|
|
524
|
-
|
|
525
499
|
id_aref = rb_intern("[]");
|
|
526
500
|
eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
|
|
527
501
|
cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
|
|
@@ -560,6 +534,7 @@ Init_ossl_x509name(void)
|
|
|
560
534
|
rb_hash_aset(hash, rb_str_new2("DC"), ia5str);
|
|
561
535
|
rb_hash_aset(hash, rb_str_new2("domainComponent"), ia5str);
|
|
562
536
|
rb_hash_aset(hash, rb_str_new2("emailAddress"), ia5str);
|
|
537
|
+
rb_obj_freeze(hash);
|
|
563
538
|
|
|
564
539
|
/*
|
|
565
540
|
* 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);
|