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_x509attr.c
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509attr_type, 0)
|
|
14
14
|
#define SetX509Attr(obj, attr) do { \
|
|
15
15
|
if (!(attr)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (attr); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509Attr(obj, attr) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_ATTRIBUTE, &ossl_x509attr_type, (attr)); \
|
|
22
22
|
if (!(attr)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ ossl_x509attr_free(void *ptr)
|
|
|
39
39
|
static const rb_data_type_t ossl_x509attr_type = {
|
|
40
40
|
"OpenSSL/X509/ATTRIBUTE",
|
|
41
41
|
{
|
|
42
|
-
|
|
42
|
+
0, ossl_x509attr_free,
|
|
43
43
|
},
|
|
44
44
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
45
45
|
};
|
|
@@ -48,21 +48,15 @@ static const rb_data_type_t ossl_x509attr_type = {
|
|
|
48
48
|
* Public
|
|
49
49
|
*/
|
|
50
50
|
VALUE
|
|
51
|
-
ossl_x509attr_new(
|
|
51
|
+
ossl_x509attr_new(X509_ATTRIBUTE *attr)
|
|
52
52
|
{
|
|
53
53
|
X509_ATTRIBUTE *new;
|
|
54
54
|
VALUE obj;
|
|
55
55
|
|
|
56
56
|
obj = NewX509Attr(cX509Attr);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/* OpenSSL 1.1.1 takes a non-const pointer */
|
|
61
|
-
new = X509_ATTRIBUTE_dup((X509_ATTRIBUTE *)attr);
|
|
62
|
-
}
|
|
63
|
-
if (!new) {
|
|
64
|
-
ossl_raise(eX509AttrError, NULL);
|
|
65
|
-
}
|
|
57
|
+
new = X509_ATTRIBUTE_dup(attr);
|
|
58
|
+
if (!new)
|
|
59
|
+
ossl_raise(eX509AttrError, "X509_ATTRIBUTE_dup");
|
|
66
60
|
SetX509Attr(obj, new);
|
|
67
61
|
|
|
68
62
|
return obj;
|
|
@@ -89,7 +83,7 @@ ossl_x509attr_alloc(VALUE klass)
|
|
|
89
83
|
|
|
90
84
|
obj = NewX509Attr(klass);
|
|
91
85
|
if (!(attr = X509_ATTRIBUTE_new()))
|
|
92
|
-
|
|
86
|
+
ossl_raise(eX509AttrError, NULL);
|
|
93
87
|
SetX509Attr(obj, attr);
|
|
94
88
|
|
|
95
89
|
return obj;
|
|
@@ -108,15 +102,15 @@ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
108
102
|
|
|
109
103
|
GetX509Attr(self, attr);
|
|
110
104
|
if(rb_scan_args(argc, argv, "11", &oid, &value) == 1){
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
105
|
+
oid = ossl_to_der_if_possible(oid);
|
|
106
|
+
StringValue(oid);
|
|
107
|
+
p = (unsigned char *)RSTRING_PTR(oid);
|
|
108
|
+
x = d2i_X509_ATTRIBUTE(&attr, &p, RSTRING_LEN(oid));
|
|
109
|
+
DATA_PTR(self) = attr;
|
|
110
|
+
if(!x){
|
|
111
|
+
ossl_raise(eX509AttrError, NULL);
|
|
112
|
+
}
|
|
113
|
+
return self;
|
|
120
114
|
}
|
|
121
115
|
rb_funcall(self, rb_intern("oid="), 1, oid);
|
|
122
116
|
rb_funcall(self, rb_intern("value="), 1, value);
|
|
@@ -124,6 +118,7 @@ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
124
118
|
return self;
|
|
125
119
|
}
|
|
126
120
|
|
|
121
|
+
/* :nodoc: */
|
|
127
122
|
static VALUE
|
|
128
123
|
ossl_x509attr_initialize_copy(VALUE self, VALUE other)
|
|
129
124
|
{
|
|
@@ -135,7 +130,7 @@ ossl_x509attr_initialize_copy(VALUE self, VALUE other)
|
|
|
135
130
|
|
|
136
131
|
attr_new = X509_ATTRIBUTE_dup(attr_other);
|
|
137
132
|
if (!attr_new)
|
|
138
|
-
|
|
133
|
+
ossl_raise(eX509AttrError, "X509_ATTRIBUTE_dup");
|
|
139
134
|
|
|
140
135
|
SetX509Attr(self, attr_new);
|
|
141
136
|
X509_ATTRIBUTE_free(attr);
|
|
@@ -159,8 +154,8 @@ ossl_x509attr_set_oid(VALUE self, VALUE oid)
|
|
|
159
154
|
obj = OBJ_txt2obj(s, 0);
|
|
160
155
|
if(!obj) ossl_raise(eX509AttrError, NULL);
|
|
161
156
|
if (!X509_ATTRIBUTE_set1_object(attr, obj)) {
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
ASN1_OBJECT_free(obj);
|
|
158
|
+
ossl_raise(eX509AttrError, "X509_ATTRIBUTE_set1_object");
|
|
164
159
|
}
|
|
165
160
|
ASN1_OBJECT_free(obj);
|
|
166
161
|
|
|
@@ -169,29 +164,18 @@ ossl_x509attr_set_oid(VALUE self, VALUE oid)
|
|
|
169
164
|
|
|
170
165
|
/*
|
|
171
166
|
* call-seq:
|
|
172
|
-
* attr.oid
|
|
167
|
+
* attr.oid -> string
|
|
168
|
+
*
|
|
169
|
+
* Returns the OID of the attribute. Returns the short name or the dotted
|
|
170
|
+
* decimal notation.
|
|
173
171
|
*/
|
|
174
172
|
static VALUE
|
|
175
173
|
ossl_x509attr_get_oid(VALUE self)
|
|
176
174
|
{
|
|
177
175
|
X509_ATTRIBUTE *attr;
|
|
178
|
-
const ASN1_OBJECT *oid;
|
|
179
|
-
BIO *out;
|
|
180
|
-
VALUE ret;
|
|
181
|
-
int nid;
|
|
182
176
|
|
|
183
177
|
GetX509Attr(self, attr);
|
|
184
|
-
|
|
185
|
-
if ((nid = OBJ_obj2nid(oid)) != NID_undef)
|
|
186
|
-
ret = rb_str_new2(OBJ_nid2sn(nid));
|
|
187
|
-
else{
|
|
188
|
-
if (!(out = BIO_new(BIO_s_mem())))
|
|
189
|
-
ossl_raise(eX509AttrError, NULL);
|
|
190
|
-
i2a_ASN1_OBJECT(out, (ASN1_OBJECT *)oid);
|
|
191
|
-
ret = ossl_membio2str(out);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return ret;
|
|
178
|
+
return ossl_asn1obj_to_string(X509_ATTRIBUTE_get0_object(attr));
|
|
195
179
|
}
|
|
196
180
|
|
|
197
181
|
/*
|
|
@@ -212,7 +196,7 @@ ossl_x509attr_set_value(VALUE self, VALUE value)
|
|
|
212
196
|
ossl_raise(eX509AttrError, "attribute value must be ASN1::Set");
|
|
213
197
|
|
|
214
198
|
if (X509_ATTRIBUTE_count(attr)) { /* populated, reset first */
|
|
215
|
-
|
|
199
|
+
ASN1_OBJECT *obj = X509_ATTRIBUTE_get0_object(attr);
|
|
216
200
|
X509_ATTRIBUTE *new_attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, 0, NULL, -1);
|
|
217
201
|
if (!new_attr) {
|
|
218
202
|
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
|
|
@@ -252,21 +236,21 @@ ossl_x509attr_get_value(VALUE self)
|
|
|
252
236
|
GetX509Attr(self, attr);
|
|
253
237
|
/* there is no X509_ATTRIBUTE_get0_set() :( */
|
|
254
238
|
if (!(sk = sk_ASN1_TYPE_new_null()))
|
|
255
|
-
|
|
239
|
+
ossl_raise(eX509AttrError, "sk_new");
|
|
256
240
|
|
|
257
241
|
count = X509_ATTRIBUTE_count(attr);
|
|
258
242
|
for (i = 0; i < count; i++)
|
|
259
|
-
sk_ASN1_TYPE_push(sk,
|
|
243
|
+
sk_ASN1_TYPE_push(sk, X509_ATTRIBUTE_get0_type(attr, i));
|
|
260
244
|
|
|
261
245
|
if ((len = i2d_ASN1_SET_ANY(sk, NULL)) <= 0) {
|
|
262
|
-
|
|
263
|
-
|
|
246
|
+
sk_ASN1_TYPE_free(sk);
|
|
247
|
+
ossl_raise(eX509AttrError, NULL);
|
|
264
248
|
}
|
|
265
249
|
str = rb_str_new(0, len);
|
|
266
250
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
267
251
|
if (i2d_ASN1_SET_ANY(sk, &p) <= 0) {
|
|
268
|
-
|
|
269
|
-
|
|
252
|
+
sk_ASN1_TYPE_free(sk);
|
|
253
|
+
ossl_raise(eX509AttrError, NULL);
|
|
270
254
|
}
|
|
271
255
|
ossl_str_adjust(str, p);
|
|
272
256
|
sk_ASN1_TYPE_free(sk);
|
|
@@ -288,11 +272,11 @@ ossl_x509attr_to_der(VALUE self)
|
|
|
288
272
|
|
|
289
273
|
GetX509Attr(self, attr);
|
|
290
274
|
if((len = i2d_X509_ATTRIBUTE(attr, NULL)) <= 0)
|
|
291
|
-
|
|
275
|
+
ossl_raise(eX509AttrError, NULL);
|
|
292
276
|
str = rb_str_new(0, len);
|
|
293
277
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
294
278
|
if(i2d_X509_ATTRIBUTE(attr, &p) <= 0)
|
|
295
|
-
|
|
279
|
+
ossl_raise(eX509AttrError, NULL);
|
|
296
280
|
ossl_str_adjust(str, p);
|
|
297
281
|
|
|
298
282
|
return str;
|
|
@@ -304,12 +288,6 @@ ossl_x509attr_to_der(VALUE self)
|
|
|
304
288
|
void
|
|
305
289
|
Init_ossl_x509attr(void)
|
|
306
290
|
{
|
|
307
|
-
#if 0
|
|
308
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
309
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
310
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
311
|
-
#endif
|
|
312
|
-
|
|
313
291
|
eX509AttrError = rb_define_class_under(mX509, "AttributeError", eOSSLError);
|
|
314
292
|
|
|
315
293
|
cX509Attr = rb_define_class_under(mX509, "Attribute", rb_cObject);
|
data/ext/openssl/ossl_x509cert.c
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509_type, 0)
|
|
14
14
|
#define SetX509(obj, x509) do { \
|
|
15
15
|
if (!(x509)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (x509); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509(obj, x509) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509, &ossl_x509_type, (x509)); \
|
|
22
22
|
if (!(x509)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ ossl_x509_free(void *ptr)
|
|
|
39
39
|
static const rb_data_type_t ossl_x509_type = {
|
|
40
40
|
"OpenSSL/X509",
|
|
41
41
|
{
|
|
42
|
-
|
|
42
|
+
0, ossl_x509_free,
|
|
43
43
|
},
|
|
44
44
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
45
45
|
};
|
|
@@ -48,21 +48,15 @@ static const rb_data_type_t ossl_x509_type = {
|
|
|
48
48
|
* Public
|
|
49
49
|
*/
|
|
50
50
|
VALUE
|
|
51
|
-
ossl_x509_new(
|
|
51
|
+
ossl_x509_new(X509 *x509)
|
|
52
52
|
{
|
|
53
53
|
X509 *new;
|
|
54
54
|
VALUE obj;
|
|
55
55
|
|
|
56
56
|
obj = NewX509(cX509Cert);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/* OpenSSL 1.1.1 takes a non-const pointer */
|
|
61
|
-
new = X509_dup((X509 *)x509);
|
|
62
|
-
}
|
|
63
|
-
if (!new) {
|
|
64
|
-
ossl_raise(eX509CertError, NULL);
|
|
65
|
-
}
|
|
57
|
+
new = X509_dup(x509);
|
|
58
|
+
if (!new)
|
|
59
|
+
ossl_raise(eX509CertError, "X509_dup");
|
|
66
60
|
SetX509(obj, new);
|
|
67
61
|
|
|
68
62
|
return obj;
|
|
@@ -121,8 +115,8 @@ ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
121
115
|
|
|
122
116
|
rb_check_frozen(self);
|
|
123
117
|
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
/* create just empty X509Cert */
|
|
119
|
+
return self;
|
|
126
120
|
}
|
|
127
121
|
arg = ossl_to_der_if_possible(arg);
|
|
128
122
|
in = ossl_obj2bio(&arg);
|
|
@@ -141,6 +135,7 @@ ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
141
135
|
return self;
|
|
142
136
|
}
|
|
143
137
|
|
|
138
|
+
/* :nodoc: */
|
|
144
139
|
static VALUE
|
|
145
140
|
ossl_x509_copy(VALUE self, VALUE other)
|
|
146
141
|
{
|
|
@@ -175,11 +170,11 @@ ossl_x509_to_der(VALUE self)
|
|
|
175
170
|
|
|
176
171
|
GetX509(self, x509);
|
|
177
172
|
if ((len = i2d_X509(x509, NULL)) <= 0)
|
|
178
|
-
|
|
173
|
+
ossl_raise(eX509CertError, NULL);
|
|
179
174
|
str = rb_str_new(0, len);
|
|
180
175
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
181
176
|
if (i2d_X509(x509, &p) <= 0)
|
|
182
|
-
|
|
177
|
+
ossl_raise(eX509CertError, NULL);
|
|
183
178
|
ossl_str_adjust(str, p);
|
|
184
179
|
|
|
185
180
|
return str;
|
|
@@ -201,8 +196,8 @@ ossl_x509_to_pem(VALUE self)
|
|
|
201
196
|
if (!out) ossl_raise(eX509CertError, NULL);
|
|
202
197
|
|
|
203
198
|
if (!PEM_write_bio_X509(out, x509)) {
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
BIO_free(out);
|
|
200
|
+
ossl_raise(eX509CertError, NULL);
|
|
206
201
|
}
|
|
207
202
|
str = ossl_membio2str(out);
|
|
208
203
|
|
|
@@ -226,8 +221,8 @@ ossl_x509_to_text(VALUE self)
|
|
|
226
221
|
if (!out) ossl_raise(eX509CertError, NULL);
|
|
227
222
|
|
|
228
223
|
if (!X509_print(out, x509)) {
|
|
229
|
-
|
|
230
|
-
|
|
224
|
+
BIO_free(out);
|
|
225
|
+
ossl_raise(eX509CertError, NULL);
|
|
231
226
|
}
|
|
232
227
|
str = ossl_membio2str(out);
|
|
233
228
|
|
|
@@ -247,7 +242,7 @@ ossl_x509_to_req(VALUE self)
|
|
|
247
242
|
|
|
248
243
|
GetX509(self, x509);
|
|
249
244
|
if (!(req = X509_to_X509_REQ(x509, NULL, EVP_md5()))) {
|
|
250
|
-
|
|
245
|
+
ossl_raise(eX509CertError, NULL);
|
|
251
246
|
}
|
|
252
247
|
obj = ossl_x509req_new(req);
|
|
253
248
|
X509_REQ_free(req);
|
|
@@ -281,11 +276,11 @@ ossl_x509_set_version(VALUE self, VALUE version)
|
|
|
281
276
|
long ver;
|
|
282
277
|
|
|
283
278
|
if ((ver = NUM2LONG(version)) < 0) {
|
|
284
|
-
|
|
279
|
+
ossl_raise(eX509CertError, "version must be >= 0!");
|
|
285
280
|
}
|
|
286
281
|
GetX509(self, x509);
|
|
287
282
|
if (!X509_set_version(x509, ver)) {
|
|
288
|
-
|
|
283
|
+
ossl_raise(eX509CertError, NULL);
|
|
289
284
|
}
|
|
290
285
|
|
|
291
286
|
return version;
|
|
@@ -323,25 +318,23 @@ ossl_x509_set_serial(VALUE self, VALUE num)
|
|
|
323
318
|
/*
|
|
324
319
|
* call-seq:
|
|
325
320
|
* cert.signature_algorithm => string
|
|
321
|
+
*
|
|
322
|
+
* Returns the signature algorithm used to sign this certificate. This returns
|
|
323
|
+
* the algorithm name found in the TBSCertificate structure, not the outer
|
|
324
|
+
* \Certificate structure.
|
|
325
|
+
*
|
|
326
|
+
* Returns the long name of the signature algorithm, or the dotted decimal
|
|
327
|
+
* notation if \OpenSSL does not define a long name for it.
|
|
326
328
|
*/
|
|
327
329
|
static VALUE
|
|
328
330
|
ossl_x509_get_signature_algorithm(VALUE self)
|
|
329
331
|
{
|
|
330
332
|
X509 *x509;
|
|
331
|
-
|
|
332
|
-
VALUE str;
|
|
333
|
+
const ASN1_OBJECT *obj;
|
|
333
334
|
|
|
334
335
|
GetX509(self, x509);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (!i2a_ASN1_OBJECT(out, X509_get0_tbs_sigalg(x509)->algorithm)) {
|
|
339
|
-
BIO_free(out);
|
|
340
|
-
ossl_raise(eX509CertError, NULL);
|
|
341
|
-
}
|
|
342
|
-
str = ossl_membio2str(out);
|
|
343
|
-
|
|
344
|
-
return str;
|
|
336
|
+
X509_ALGOR_get0(&obj, NULL, NULL, X509_get0_tbs_sigalg(x509));
|
|
337
|
+
return ossl_asn1obj_to_string_long_name(obj);
|
|
345
338
|
}
|
|
346
339
|
|
|
347
340
|
/*
|
|
@@ -352,11 +345,11 @@ static VALUE
|
|
|
352
345
|
ossl_x509_get_subject(VALUE self)
|
|
353
346
|
{
|
|
354
347
|
X509 *x509;
|
|
355
|
-
|
|
348
|
+
X509_NAME *name;
|
|
356
349
|
|
|
357
350
|
GetX509(self, x509);
|
|
358
351
|
if (!(name = X509_get_subject_name(x509))) { /* NO DUP - don't free! */
|
|
359
|
-
|
|
352
|
+
ossl_raise(eX509CertError, NULL);
|
|
360
353
|
}
|
|
361
354
|
|
|
362
355
|
return ossl_x509name_new(name);
|
|
@@ -373,7 +366,7 @@ ossl_x509_set_subject(VALUE self, VALUE subject)
|
|
|
373
366
|
|
|
374
367
|
GetX509(self, x509);
|
|
375
368
|
if (!X509_set_subject_name(x509, GetX509NamePtr(subject))) { /* DUPs name */
|
|
376
|
-
|
|
369
|
+
ossl_raise(eX509CertError, NULL);
|
|
377
370
|
}
|
|
378
371
|
|
|
379
372
|
return subject;
|
|
@@ -387,11 +380,11 @@ static VALUE
|
|
|
387
380
|
ossl_x509_get_issuer(VALUE self)
|
|
388
381
|
{
|
|
389
382
|
X509 *x509;
|
|
390
|
-
|
|
383
|
+
X509_NAME *name;
|
|
391
384
|
|
|
392
385
|
GetX509(self, x509);
|
|
393
386
|
if(!(name = X509_get_issuer_name(x509))) { /* NO DUP - don't free! */
|
|
394
|
-
|
|
387
|
+
ossl_raise(eX509CertError, NULL);
|
|
395
388
|
}
|
|
396
389
|
|
|
397
390
|
return ossl_x509name_new(name);
|
|
@@ -408,7 +401,7 @@ ossl_x509_set_issuer(VALUE self, VALUE issuer)
|
|
|
408
401
|
|
|
409
402
|
GetX509(self, x509);
|
|
410
403
|
if (!X509_set_issuer_name(x509, GetX509NamePtr(issuer))) { /* DUPs name */
|
|
411
|
-
|
|
404
|
+
ossl_raise(eX509CertError, NULL);
|
|
412
405
|
}
|
|
413
406
|
|
|
414
407
|
return issuer;
|
|
@@ -426,7 +419,7 @@ ossl_x509_get_not_before(VALUE self)
|
|
|
426
419
|
|
|
427
420
|
GetX509(self, x509);
|
|
428
421
|
if (!(asn1time = X509_get0_notBefore(x509))) {
|
|
429
|
-
|
|
422
|
+
ossl_raise(eX509CertError, NULL);
|
|
430
423
|
}
|
|
431
424
|
|
|
432
425
|
return asn1time_to_time(asn1time);
|
|
@@ -445,8 +438,8 @@ ossl_x509_set_not_before(VALUE self, VALUE time)
|
|
|
445
438
|
GetX509(self, x509);
|
|
446
439
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
|
447
440
|
if (!X509_set1_notBefore(x509, asn1time)) {
|
|
448
|
-
|
|
449
|
-
|
|
441
|
+
ASN1_TIME_free(asn1time);
|
|
442
|
+
ossl_raise(eX509CertError, "X509_set_notBefore");
|
|
450
443
|
}
|
|
451
444
|
ASN1_TIME_free(asn1time);
|
|
452
445
|
|
|
@@ -465,7 +458,7 @@ ossl_x509_get_not_after(VALUE self)
|
|
|
465
458
|
|
|
466
459
|
GetX509(self, x509);
|
|
467
460
|
if (!(asn1time = X509_get0_notAfter(x509))) {
|
|
468
|
-
|
|
461
|
+
ossl_raise(eX509CertError, NULL);
|
|
469
462
|
}
|
|
470
463
|
|
|
471
464
|
return asn1time_to_time(asn1time);
|
|
@@ -484,8 +477,8 @@ ossl_x509_set_not_after(VALUE self, VALUE time)
|
|
|
484
477
|
GetX509(self, x509);
|
|
485
478
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
|
486
479
|
if (!X509_set1_notAfter(x509, asn1time)) {
|
|
487
|
-
|
|
488
|
-
|
|
480
|
+
ASN1_TIME_free(asn1time);
|
|
481
|
+
ossl_raise(eX509CertError, "X509_set_notAfter");
|
|
489
482
|
}
|
|
490
483
|
ASN1_TIME_free(asn1time);
|
|
491
484
|
|
|
@@ -504,10 +497,10 @@ ossl_x509_get_public_key(VALUE self)
|
|
|
504
497
|
|
|
505
498
|
GetX509(self, x509);
|
|
506
499
|
if (!(pkey = X509_get_pubkey(x509))) { /* adds an reference */
|
|
507
|
-
|
|
500
|
+
ossl_raise(eX509CertError, NULL);
|
|
508
501
|
}
|
|
509
502
|
|
|
510
|
-
return
|
|
503
|
+
return ossl_pkey_wrap(pkey);
|
|
511
504
|
}
|
|
512
505
|
|
|
513
506
|
/*
|
|
@@ -524,7 +517,7 @@ ossl_x509_set_public_key(VALUE self, VALUE key)
|
|
|
524
517
|
pkey = GetPKeyPtr(key);
|
|
525
518
|
ossl_pkey_check_public_key(pkey);
|
|
526
519
|
if (!X509_set_pubkey(x509, pkey))
|
|
527
|
-
|
|
520
|
+
ossl_raise(eX509CertError, "X509_set_pubkey");
|
|
528
521
|
return key;
|
|
529
522
|
}
|
|
530
523
|
|
|
@@ -538,17 +531,14 @@ ossl_x509_sign(VALUE self, VALUE key, VALUE digest)
|
|
|
538
531
|
X509 *x509;
|
|
539
532
|
EVP_PKEY *pkey;
|
|
540
533
|
const EVP_MD *md;
|
|
534
|
+
VALUE md_holder;
|
|
541
535
|
|
|
542
536
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
} else {
|
|
546
|
-
md = ossl_evp_get_digestbyname(digest);
|
|
547
|
-
}
|
|
537
|
+
/* NULL needed for some key types, e.g. Ed25519 */
|
|
538
|
+
md = NIL_P(digest) ? NULL : ossl_evp_md_fetch(digest, &md_holder);
|
|
548
539
|
GetX509(self, x509);
|
|
549
|
-
if (!X509_sign(x509, pkey, md))
|
|
550
|
-
|
|
551
|
-
}
|
|
540
|
+
if (!X509_sign(x509, pkey, md))
|
|
541
|
+
ossl_raise(eX509CertError, "X509_sign");
|
|
552
542
|
|
|
553
543
|
return self;
|
|
554
544
|
}
|
|
@@ -571,12 +561,12 @@ ossl_x509_verify(VALUE self, VALUE key)
|
|
|
571
561
|
ossl_pkey_check_public_key(pkey);
|
|
572
562
|
switch (X509_verify(x509, pkey)) {
|
|
573
563
|
case 1:
|
|
574
|
-
|
|
564
|
+
return Qtrue;
|
|
575
565
|
case 0:
|
|
576
|
-
|
|
577
|
-
|
|
566
|
+
ossl_clear_error();
|
|
567
|
+
return Qfalse;
|
|
578
568
|
default:
|
|
579
|
-
|
|
569
|
+
ossl_raise(eX509CertError, NULL);
|
|
580
570
|
}
|
|
581
571
|
}
|
|
582
572
|
|
|
@@ -597,8 +587,8 @@ ossl_x509_check_private_key(VALUE self, VALUE key)
|
|
|
597
587
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
|
598
588
|
GetX509(self, x509);
|
|
599
589
|
if (!X509_check_private_key(x509, pkey)) {
|
|
600
|
-
|
|
601
|
-
|
|
590
|
+
ossl_clear_error();
|
|
591
|
+
return Qfalse;
|
|
602
592
|
}
|
|
603
593
|
|
|
604
594
|
return Qtrue;
|
|
@@ -613,17 +603,15 @@ ossl_x509_get_extensions(VALUE self)
|
|
|
613
603
|
{
|
|
614
604
|
X509 *x509;
|
|
615
605
|
int count, i;
|
|
606
|
+
X509_EXTENSION *ext;
|
|
616
607
|
VALUE ary;
|
|
617
608
|
|
|
618
609
|
GetX509(self, x509);
|
|
619
610
|
count = X509_get_ext_count(x509);
|
|
620
|
-
|
|
621
|
-
return rb_ary_new();
|
|
622
|
-
}
|
|
623
|
-
ary = rb_ary_new2(count);
|
|
611
|
+
ary = rb_ary_new_capa(count);
|
|
624
612
|
for (i=0; i<count; i++) {
|
|
625
|
-
|
|
626
|
-
|
|
613
|
+
ext = X509_get_ext(x509, i); /* NO DUP - don't free! */
|
|
614
|
+
rb_ary_push(ary, ossl_x509ext_new(ext));
|
|
627
615
|
}
|
|
628
616
|
|
|
629
617
|
return ary;
|
|
@@ -643,16 +631,16 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
|
|
|
643
631
|
Check_Type(ary, T_ARRAY);
|
|
644
632
|
/* All ary's members should be X509Extension */
|
|
645
633
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
646
|
-
|
|
634
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
|
|
647
635
|
}
|
|
648
636
|
GetX509(self, x509);
|
|
649
637
|
for (i = X509_get_ext_count(x509); i > 0; i--)
|
|
650
638
|
X509_EXTENSION_free(X509_delete_ext(x509, 0));
|
|
651
639
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
640
|
+
ext = GetX509ExtPtr(RARRAY_AREF(ary, i));
|
|
641
|
+
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext */
|
|
642
|
+
ossl_raise(eX509CertError, "X509_add_ext");
|
|
643
|
+
}
|
|
656
644
|
}
|
|
657
645
|
|
|
658
646
|
return ary;
|
|
@@ -671,32 +659,24 @@ ossl_x509_add_extension(VALUE self, VALUE extension)
|
|
|
671
659
|
GetX509(self, x509);
|
|
672
660
|
ext = GetX509ExtPtr(extension);
|
|
673
661
|
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
|
|
674
|
-
|
|
662
|
+
ossl_raise(eX509CertError, NULL);
|
|
675
663
|
}
|
|
676
664
|
|
|
677
665
|
return extension;
|
|
678
666
|
}
|
|
679
667
|
|
|
680
|
-
static VALUE
|
|
681
|
-
ossl_x509_inspect(VALUE self)
|
|
682
|
-
{
|
|
683
|
-
return rb_sprintf("#<%"PRIsVALUE": subject=%+"PRIsVALUE", "
|
|
684
|
-
"issuer=%+"PRIsVALUE", serial=%+"PRIsVALUE", "
|
|
685
|
-
"not_before=%+"PRIsVALUE", not_after=%+"PRIsVALUE">",
|
|
686
|
-
rb_obj_class(self),
|
|
687
|
-
ossl_x509_get_subject(self),
|
|
688
|
-
ossl_x509_get_issuer(self),
|
|
689
|
-
ossl_x509_get_serial(self),
|
|
690
|
-
ossl_x509_get_not_before(self),
|
|
691
|
-
ossl_x509_get_not_after(self));
|
|
692
|
-
}
|
|
693
|
-
|
|
694
668
|
/*
|
|
695
669
|
* call-seq:
|
|
696
670
|
* cert1 == cert2 -> true | false
|
|
697
671
|
*
|
|
698
672
|
* Compares the two certificates. Note that this takes into account all fields,
|
|
699
673
|
* not just the issuer name and the serial number.
|
|
674
|
+
*
|
|
675
|
+
* This method uses X509_cmp() from OpenSSL, which compares certificates based
|
|
676
|
+
* on their cached DER encodings. The comparison can be unreliable if a
|
|
677
|
+
* certificate is incomplete.
|
|
678
|
+
*
|
|
679
|
+
* See also the man page X509_cmp(3).
|
|
700
680
|
*/
|
|
701
681
|
static VALUE
|
|
702
682
|
ossl_x509_eq(VALUE self, VALUE other)
|
|
@@ -705,13 +685,12 @@ ossl_x509_eq(VALUE self, VALUE other)
|
|
|
705
685
|
|
|
706
686
|
GetX509(self, a);
|
|
707
687
|
if (!rb_obj_is_kind_of(other, cX509Cert))
|
|
708
|
-
|
|
688
|
+
return Qfalse;
|
|
709
689
|
GetX509(other, b);
|
|
710
690
|
|
|
711
691
|
return !X509_cmp(a, b) ? Qtrue : Qfalse;
|
|
712
692
|
}
|
|
713
693
|
|
|
714
|
-
#ifdef HAVE_I2D_RE_X509_TBS
|
|
715
694
|
/*
|
|
716
695
|
* call-seq:
|
|
717
696
|
* cert.tbs_bytes => string
|
|
@@ -741,7 +720,6 @@ ossl_x509_tbs_bytes(VALUE self)
|
|
|
741
720
|
|
|
742
721
|
return str;
|
|
743
722
|
}
|
|
744
|
-
#endif
|
|
745
723
|
|
|
746
724
|
struct load_chained_certificates_arguments {
|
|
747
725
|
VALUE certificates;
|
|
@@ -802,7 +780,7 @@ load_chained_certificates_PEM(BIO *in) {
|
|
|
802
780
|
certificates = load_chained_certificates_append(Qnil, certificate);
|
|
803
781
|
|
|
804
782
|
while ((certificate = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
|
|
805
|
-
|
|
783
|
+
load_chained_certificates_append(certificates, certificate);
|
|
806
784
|
}
|
|
807
785
|
|
|
808
786
|
/* We tried to read one more certificate but could not read start line: */
|
|
@@ -900,12 +878,6 @@ ossl_x509_load(VALUE klass, VALUE buffer)
|
|
|
900
878
|
void
|
|
901
879
|
Init_ossl_x509cert(void)
|
|
902
880
|
{
|
|
903
|
-
#if 0
|
|
904
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
905
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
906
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
907
|
-
#endif
|
|
908
|
-
|
|
909
881
|
eX509CertError = rb_define_class_under(mX509, "CertificateError", eOSSLError);
|
|
910
882
|
|
|
911
883
|
/* Document-class: OpenSSL::X509::Certificate
|
|
@@ -1033,9 +1005,6 @@ Init_ossl_x509cert(void)
|
|
|
1033
1005
|
rb_define_method(cX509Cert, "extensions", ossl_x509_get_extensions, 0);
|
|
1034
1006
|
rb_define_method(cX509Cert, "extensions=", ossl_x509_set_extensions, 1);
|
|
1035
1007
|
rb_define_method(cX509Cert, "add_extension", ossl_x509_add_extension, 1);
|
|
1036
|
-
rb_define_method(cX509Cert, "inspect", ossl_x509_inspect, 0);
|
|
1037
1008
|
rb_define_method(cX509Cert, "==", ossl_x509_eq, 1);
|
|
1038
|
-
#ifdef HAVE_I2D_RE_X509_TBS
|
|
1039
1009
|
rb_define_method(cX509Cert, "tbs_bytes", ossl_x509_tbs_bytes, 0);
|
|
1040
|
-
#endif
|
|
1041
1010
|
}
|