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
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509rev_type, 0)
|
|
14
14
|
#define SetX509Rev(obj, rev) do { \
|
|
15
15
|
if (!(rev)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (rev); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509Rev(obj, rev) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_REVOKED, &ossl_x509rev_type, (rev)); \
|
|
22
22
|
if (!(rev)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ ossl_x509rev_free(void *ptr)
|
|
|
39
39
|
static const rb_data_type_t ossl_x509rev_type = {
|
|
40
40
|
"OpenSSL/X509/REV",
|
|
41
41
|
{
|
|
42
|
-
|
|
42
|
+
0, ossl_x509rev_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_x509rev_type = {
|
|
|
48
48
|
* PUBLIC
|
|
49
49
|
*/
|
|
50
50
|
VALUE
|
|
51
|
-
ossl_x509revoked_new(
|
|
51
|
+
ossl_x509revoked_new(X509_REVOKED *rev)
|
|
52
52
|
{
|
|
53
53
|
X509_REVOKED *new;
|
|
54
54
|
VALUE obj;
|
|
55
55
|
|
|
56
56
|
obj = NewX509Rev(cX509Rev);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/* OpenSSL 1.1.1 takes a non-const pointer */
|
|
61
|
-
new = X509_REVOKED_dup((X509_REVOKED *)rev);
|
|
62
|
-
}
|
|
63
|
-
if (!new) {
|
|
64
|
-
ossl_raise(eX509RevError, NULL);
|
|
65
|
-
}
|
|
57
|
+
new = X509_REVOKED_dup(rev);
|
|
58
|
+
if (!new)
|
|
59
|
+
ossl_raise(eX509RevError, "X509_REVOKED_dup");
|
|
66
60
|
SetX509Rev(obj, new);
|
|
67
61
|
|
|
68
62
|
return obj;
|
|
@@ -75,7 +69,7 @@ DupX509RevokedPtr(VALUE obj)
|
|
|
75
69
|
|
|
76
70
|
GetX509Rev(obj, rev);
|
|
77
71
|
if (!(new = X509_REVOKED_dup(rev))) {
|
|
78
|
-
|
|
72
|
+
ossl_raise(eX509RevError, NULL);
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
return new;
|
|
@@ -92,7 +86,7 @@ ossl_x509revoked_alloc(VALUE klass)
|
|
|
92
86
|
|
|
93
87
|
obj = NewX509Rev(klass);
|
|
94
88
|
if (!(rev = X509_REVOKED_new())) {
|
|
95
|
-
|
|
89
|
+
ossl_raise(eX509RevError, NULL);
|
|
96
90
|
}
|
|
97
91
|
SetX509Rev(obj, rev);
|
|
98
92
|
|
|
@@ -106,6 +100,7 @@ ossl_x509revoked_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
106
100
|
return self;
|
|
107
101
|
}
|
|
108
102
|
|
|
103
|
+
/* :nodoc: */
|
|
109
104
|
static VALUE
|
|
110
105
|
ossl_x509revoked_initialize_copy(VALUE self, VALUE other)
|
|
111
106
|
{
|
|
@@ -117,7 +112,7 @@ ossl_x509revoked_initialize_copy(VALUE self, VALUE other)
|
|
|
117
112
|
|
|
118
113
|
rev_new = X509_REVOKED_dup(rev_other);
|
|
119
114
|
if (!rev_new)
|
|
120
|
-
|
|
115
|
+
ossl_raise(eX509RevError, "X509_REVOKED_dup");
|
|
121
116
|
|
|
122
117
|
SetX509Rev(self, rev_new);
|
|
123
118
|
X509_REVOKED_free(rev);
|
|
@@ -144,8 +139,8 @@ ossl_x509revoked_set_serial(VALUE self, VALUE num)
|
|
|
144
139
|
GetX509Rev(self, rev);
|
|
145
140
|
asn1int = num_to_asn1integer(num, NULL);
|
|
146
141
|
if (!X509_REVOKED_set_serialNumber(rev, asn1int)) {
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
ASN1_INTEGER_free(asn1int);
|
|
143
|
+
ossl_raise(eX509RevError, "X509_REVOKED_set_serialNumber");
|
|
149
144
|
}
|
|
150
145
|
ASN1_INTEGER_free(asn1int);
|
|
151
146
|
|
|
@@ -161,7 +156,7 @@ ossl_x509revoked_get_time(VALUE self)
|
|
|
161
156
|
GetX509Rev(self, rev);
|
|
162
157
|
time = X509_REVOKED_get0_revocationDate(rev);
|
|
163
158
|
if (!time)
|
|
164
|
-
|
|
159
|
+
return Qnil;
|
|
165
160
|
|
|
166
161
|
return asn1time_to_time(time);
|
|
167
162
|
}
|
|
@@ -175,8 +170,8 @@ ossl_x509revoked_set_time(VALUE self, VALUE time)
|
|
|
175
170
|
GetX509Rev(self, rev);
|
|
176
171
|
asn1time = ossl_x509_time_adjust(NULL, time);
|
|
177
172
|
if (!X509_REVOKED_set_revocationDate(rev, asn1time)) {
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
ASN1_TIME_free(asn1time);
|
|
174
|
+
ossl_raise(eX509RevError, "X509_REVOKED_set_revocationDate");
|
|
180
175
|
}
|
|
181
176
|
ASN1_TIME_free(asn1time);
|
|
182
177
|
|
|
@@ -190,19 +185,15 @@ ossl_x509revoked_get_extensions(VALUE self)
|
|
|
190
185
|
{
|
|
191
186
|
X509_REVOKED *rev;
|
|
192
187
|
int count, i;
|
|
193
|
-
|
|
188
|
+
X509_EXTENSION *ext;
|
|
194
189
|
VALUE ary;
|
|
195
190
|
|
|
196
191
|
GetX509Rev(self, rev);
|
|
197
192
|
count = X509_REVOKED_get_ext_count(rev);
|
|
198
|
-
|
|
199
|
-
OSSL_Debug("count < 0???");
|
|
200
|
-
return rb_ary_new();
|
|
201
|
-
}
|
|
202
|
-
ary = rb_ary_new2(count);
|
|
193
|
+
ary = rb_ary_new_capa(count);
|
|
203
194
|
for (i=0; i<count; i++) {
|
|
204
|
-
|
|
205
|
-
|
|
195
|
+
ext = X509_REVOKED_get_ext(rev, i);
|
|
196
|
+
rb_ary_push(ary, ossl_x509ext_new(ext));
|
|
206
197
|
}
|
|
207
198
|
|
|
208
199
|
return ary;
|
|
@@ -221,17 +212,17 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
|
|
|
221
212
|
|
|
222
213
|
Check_Type(ary, T_ARRAY);
|
|
223
214
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
224
|
-
|
|
215
|
+
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Ext);
|
|
225
216
|
}
|
|
226
217
|
GetX509Rev(self, rev);
|
|
227
218
|
for (i = X509_REVOKED_get_ext_count(rev); i > 0; i--)
|
|
228
219
|
X509_EXTENSION_free(X509_REVOKED_delete_ext(rev, 0));
|
|
229
220
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
221
|
+
item = RARRAY_AREF(ary, i);
|
|
222
|
+
ext = GetX509ExtPtr(item);
|
|
223
|
+
if(!X509_REVOKED_add_ext(rev, ext, -1)) {
|
|
224
|
+
ossl_raise(eX509RevError, "X509_REVOKED_add_ext");
|
|
225
|
+
}
|
|
235
226
|
}
|
|
236
227
|
|
|
237
228
|
return ary;
|
|
@@ -244,7 +235,7 @@ ossl_x509revoked_add_extension(VALUE self, VALUE ext)
|
|
|
244
235
|
|
|
245
236
|
GetX509Rev(self, rev);
|
|
246
237
|
if (!X509_REVOKED_add_ext(rev, GetX509ExtPtr(ext), -1)) {
|
|
247
|
-
|
|
238
|
+
ossl_raise(eX509RevError, NULL);
|
|
248
239
|
}
|
|
249
240
|
|
|
250
241
|
return ext;
|
|
@@ -261,11 +252,11 @@ ossl_x509revoked_to_der(VALUE self)
|
|
|
261
252
|
GetX509Rev(self, rev);
|
|
262
253
|
len = i2d_X509_REVOKED(rev, NULL);
|
|
263
254
|
if (len <= 0)
|
|
264
|
-
|
|
255
|
+
ossl_raise(eX509RevError, "i2d_X509_REVOKED");
|
|
265
256
|
str = rb_str_new(NULL, len);
|
|
266
257
|
p = (unsigned char *)RSTRING_PTR(str);
|
|
267
258
|
if (i2d_X509_REVOKED(rev, &p) <= 0)
|
|
268
|
-
|
|
259
|
+
ossl_raise(eX509RevError, "i2d_X509_REVOKED");
|
|
269
260
|
ossl_str_adjust(str, p);
|
|
270
261
|
return str;
|
|
271
262
|
}
|
|
@@ -276,12 +267,6 @@ ossl_x509revoked_to_der(VALUE self)
|
|
|
276
267
|
void
|
|
277
268
|
Init_ossl_x509revoked(void)
|
|
278
269
|
{
|
|
279
|
-
#if 0
|
|
280
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
281
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
282
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
283
|
-
#endif
|
|
284
|
-
|
|
285
270
|
eX509RevError = rb_define_class_under(mX509, "RevokedError", eOSSLError);
|
|
286
271
|
|
|
287
272
|
cX509Rev = rb_define_class_under(mX509, "Revoked", rb_cObject);
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
TypedData_Wrap_Struct((klass), &ossl_x509store_type, 0)
|
|
14
14
|
#define SetX509Store(obj, st) do { \
|
|
15
15
|
if (!(st)) { \
|
|
16
|
-
|
|
16
|
+
ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \
|
|
17
17
|
} \
|
|
18
18
|
RTYPEDDATA_DATA(obj) = (st); \
|
|
19
19
|
} while (0)
|
|
20
20
|
#define GetX509Store(obj, st) do { \
|
|
21
21
|
TypedData_Get_Struct((obj), X509_STORE, &ossl_x509store_type, (st)); \
|
|
22
22
|
if (!(st)) { \
|
|
23
|
-
|
|
23
|
+
ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \
|
|
24
24
|
} \
|
|
25
25
|
} while (0)
|
|
26
26
|
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
TypedData_Wrap_Struct((klass), &ossl_x509stctx_type, 0)
|
|
29
29
|
#define SetX509StCtx(obj, ctx) do { \
|
|
30
30
|
if (!(ctx)) { \
|
|
31
|
-
|
|
31
|
+
ossl_raise(rb_eRuntimeError, "STORE_CTX wasn't initialized!"); \
|
|
32
32
|
} \
|
|
33
33
|
RTYPEDDATA_DATA(obj) = (ctx); \
|
|
34
34
|
} while (0)
|
|
35
35
|
#define GetX509StCtx(obj, ctx) do { \
|
|
36
36
|
TypedData_Get_Struct((obj), X509_STORE_CTX, &ossl_x509stctx_type, (ctx)); \
|
|
37
37
|
if (!(ctx)) { \
|
|
38
|
-
|
|
38
|
+
ossl_raise(rb_eRuntimeError, "STORE_CTX is out of scope!"); \
|
|
39
39
|
} \
|
|
40
40
|
} while (0)
|
|
41
41
|
|
|
@@ -62,7 +62,7 @@ call_verify_cb_proc(VALUE arg)
|
|
|
62
62
|
{
|
|
63
63
|
struct ossl_verify_cb_args *args = (struct ossl_verify_cb_args *)arg;
|
|
64
64
|
return rb_funcall(args->proc, rb_intern("call"), 2,
|
|
65
|
-
|
|
65
|
+
args->preverify_ok, args->store_ctx);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
int
|
|
@@ -73,33 +73,33 @@ ossl_verify_cb_call(VALUE proc, int ok, X509_STORE_CTX *ctx)
|
|
|
73
73
|
int state;
|
|
74
74
|
|
|
75
75
|
if (NIL_P(proc))
|
|
76
|
-
|
|
76
|
+
return ok;
|
|
77
77
|
|
|
78
78
|
ret = Qfalse;
|
|
79
79
|
rctx = rb_protect(ossl_x509stctx_new_i, (VALUE)ctx, &state);
|
|
80
80
|
if (state) {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
rb_set_errinfo(Qnil);
|
|
82
|
+
rb_warn("StoreContext initialization failure");
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
args.proc = proc;
|
|
86
|
+
args.preverify_ok = ok ? Qtrue : Qfalse;
|
|
87
|
+
args.store_ctx = rctx;
|
|
88
|
+
ret = rb_protect(call_verify_cb_proc, (VALUE)&args, &state);
|
|
89
|
+
if (state) {
|
|
90
|
+
rb_set_errinfo(Qnil);
|
|
91
|
+
rb_warn("exception in verify_callback is ignored");
|
|
92
|
+
}
|
|
93
|
+
RTYPEDDATA_DATA(rctx) = NULL;
|
|
94
94
|
}
|
|
95
95
|
if (ret == Qtrue) {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
X509_STORE_CTX_set_error(ctx, X509_V_OK);
|
|
97
|
+
ok = 1;
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
if (X509_STORE_CTX_get_error(ctx) == X509_V_OK)
|
|
101
|
+
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REJECTED);
|
|
102
|
+
ok = 0;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
return ok;
|
|
@@ -159,10 +159,10 @@ x509store_verify_cb(int ok, X509_STORE_CTX *ctx)
|
|
|
159
159
|
|
|
160
160
|
proc = (VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx);
|
|
161
161
|
if (!proc)
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
proc = (VALUE)X509_STORE_get_ex_data(X509_STORE_CTX_get0_store(ctx),
|
|
163
|
+
store_ex_verify_cb_idx);
|
|
164
164
|
if (!proc)
|
|
165
|
-
|
|
165
|
+
return ok;
|
|
166
166
|
|
|
167
167
|
return ossl_verify_cb_call(proc, ok, ctx);
|
|
168
168
|
}
|
|
@@ -191,8 +191,8 @@ ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
|
|
|
191
191
|
|
|
192
192
|
GetX509Store(self, store);
|
|
193
193
|
rb_iv_set(self, "@verify_callback", cb);
|
|
194
|
-
// We don't need to trigger a write barrier because `rb_iv_set` did it.
|
|
195
194
|
X509_STORE_set_ex_data(store, store_ex_verify_cb_idx, (void *)cb);
|
|
195
|
+
RB_OBJ_WRITTEN(self, Qundef, cb);
|
|
196
196
|
|
|
197
197
|
return cb;
|
|
198
198
|
}
|
|
@@ -212,10 +212,6 @@ ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
212
212
|
GetX509Store(self, store);
|
|
213
213
|
if (argc != 0)
|
|
214
214
|
rb_warn("OpenSSL::X509::Store.new does not take any arguments");
|
|
215
|
-
#if !defined(HAVE_OPAQUE_OPENSSL)
|
|
216
|
-
/* [Bug #405] [Bug #1678] [Bug #3000]; already fixed? */
|
|
217
|
-
store->ex_data.sk = NULL;
|
|
218
|
-
#endif
|
|
219
215
|
X509_STORE_set_verify_cb(store, x509store_verify_cb);
|
|
220
216
|
ossl_x509store_set_vfy_cb(self, Qnil);
|
|
221
217
|
|
|
@@ -332,11 +328,7 @@ ossl_x509store_set_time(VALUE self, VALUE time)
|
|
|
332
328
|
X509_VERIFY_PARAM *param;
|
|
333
329
|
|
|
334
330
|
GetX509Store(self, store);
|
|
335
|
-
#ifdef HAVE_X509_STORE_GET0_PARAM
|
|
336
331
|
param = X509_STORE_get0_param(store);
|
|
337
|
-
#else
|
|
338
|
-
param = store->param;
|
|
339
|
-
#endif
|
|
340
332
|
X509_VERIFY_PARAM_set_time(param, NUM2LONG(rb_Integer(time)));
|
|
341
333
|
return time;
|
|
342
334
|
}
|
|
@@ -365,15 +357,6 @@ ossl_x509store_add_file(VALUE self, VALUE file)
|
|
|
365
357
|
ossl_raise(eX509StoreError, "X509_STORE_add_lookup");
|
|
366
358
|
if (X509_LOOKUP_load_file(lookup, path, X509_FILETYPE_PEM) != 1)
|
|
367
359
|
ossl_raise(eX509StoreError, "X509_LOOKUP_load_file");
|
|
368
|
-
#if OPENSSL_VERSION_NUMBER < 0x10101000 || defined(LIBRESSL_VERSION_NUMBER)
|
|
369
|
-
/*
|
|
370
|
-
* X509_load_cert_crl_file() which is called from X509_LOOKUP_load_file()
|
|
371
|
-
* did not check the return value of X509_STORE_add_{cert,crl}(), leaking
|
|
372
|
-
* "cert already in hash table" errors on the error queue, if duplicate
|
|
373
|
-
* certificates are found. This will be fixed by OpenSSL 1.1.1.
|
|
374
|
-
*/
|
|
375
|
-
ossl_clear_error();
|
|
376
|
-
#endif
|
|
377
360
|
|
|
378
361
|
return self;
|
|
379
362
|
}
|
|
@@ -501,7 +484,7 @@ ossl_x509store_verify(int argc, VALUE *argv, VALUE self)
|
|
|
501
484
|
rb_scan_args(argc, argv, "11", &cert, &chain);
|
|
502
485
|
ctx = rb_funcall(cX509StoreContext, rb_intern("new"), 3, self, cert, chain);
|
|
503
486
|
proc = rb_block_given_p() ? rb_block_proc() :
|
|
504
|
-
|
|
487
|
+
rb_iv_get(self, "@verify_callback");
|
|
505
488
|
rb_iv_set(ctx, "@verify_callback", proc);
|
|
506
489
|
result = rb_funcall(ctx, rb_intern("verify"), 0);
|
|
507
490
|
|
|
@@ -529,8 +512,10 @@ static void
|
|
|
529
512
|
ossl_x509stctx_free(void *ptr)
|
|
530
513
|
{
|
|
531
514
|
X509_STORE_CTX *ctx = ptr;
|
|
532
|
-
|
|
533
|
-
|
|
515
|
+
if (X509_STORE_CTX_get0_untrusted(ctx))
|
|
516
|
+
sk_X509_pop_free(X509_STORE_CTX_get0_untrusted(ctx), X509_free);
|
|
517
|
+
if (X509_STORE_CTX_get0_cert(ctx))
|
|
518
|
+
X509_free(X509_STORE_CTX_get0_cert(ctx));
|
|
534
519
|
X509_STORE_CTX_free(ctx);
|
|
535
520
|
}
|
|
536
521
|
|
|
@@ -626,6 +611,7 @@ ossl_x509stctx_verify(VALUE self)
|
|
|
626
611
|
GetX509StCtx(self, ctx);
|
|
627
612
|
VALUE cb = rb_iv_get(self, "@verify_callback");
|
|
628
613
|
X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx, (void *)cb);
|
|
614
|
+
RB_OBJ_WRITTEN(self, Qundef, cb);
|
|
629
615
|
|
|
630
616
|
switch (X509_verify_cert(ctx)) {
|
|
631
617
|
case 1:
|
|
@@ -750,10 +736,14 @@ static VALUE
|
|
|
750
736
|
ossl_x509stctx_get_curr_cert(VALUE self)
|
|
751
737
|
{
|
|
752
738
|
X509_STORE_CTX *ctx;
|
|
739
|
+
X509 *x509;
|
|
753
740
|
|
|
754
741
|
GetX509StCtx(self, ctx);
|
|
742
|
+
x509 = X509_STORE_CTX_get_current_cert(ctx);
|
|
743
|
+
if (!x509)
|
|
744
|
+
return Qnil;
|
|
755
745
|
|
|
756
|
-
return ossl_x509_new(
|
|
746
|
+
return ossl_x509_new(x509);
|
|
757
747
|
}
|
|
758
748
|
|
|
759
749
|
/*
|
|
@@ -768,12 +758,12 @@ static VALUE
|
|
|
768
758
|
ossl_x509stctx_get_curr_crl(VALUE self)
|
|
769
759
|
{
|
|
770
760
|
X509_STORE_CTX *ctx;
|
|
771
|
-
|
|
761
|
+
X509_CRL *crl;
|
|
772
762
|
|
|
773
763
|
GetX509StCtx(self, ctx);
|
|
774
764
|
crl = X509_STORE_CTX_get0_current_crl(ctx);
|
|
775
765
|
if (!crl)
|
|
776
|
-
|
|
766
|
+
return Qnil;
|
|
777
767
|
|
|
778
768
|
return ossl_x509crl_new(crl);
|
|
779
769
|
}
|
|
@@ -869,19 +859,13 @@ void
|
|
|
869
859
|
Init_ossl_x509store(void)
|
|
870
860
|
{
|
|
871
861
|
#undef rb_intern
|
|
872
|
-
#if 0
|
|
873
|
-
mOSSL = rb_define_module("OpenSSL");
|
|
874
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
875
|
-
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
876
|
-
#endif
|
|
877
|
-
|
|
878
862
|
/* Register ext_data slot for verify callback Proc */
|
|
879
863
|
stctx_ex_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, (void *)"stctx_ex_verify_cb_idx", 0, 0, 0);
|
|
880
864
|
if (stctx_ex_verify_cb_idx < 0)
|
|
881
|
-
|
|
865
|
+
ossl_raise(eOSSLError, "X509_STORE_CTX_get_ex_new_index");
|
|
882
866
|
store_ex_verify_cb_idx = X509_STORE_get_ex_new_index(0, (void *)"store_ex_verify_cb_idx", 0, 0, 0);
|
|
883
867
|
if (store_ex_verify_cb_idx < 0)
|
|
884
|
-
|
|
868
|
+
ossl_raise(eOSSLError, "X509_STORE_get_ex_new_index");
|
|
885
869
|
|
|
886
870
|
eX509StoreError = rb_define_class_under(mX509, "StoreError", eOSSLError);
|
|
887
871
|
|
data/lib/openssl/buffering.rb
CHANGED
|
@@ -24,25 +24,21 @@ module OpenSSL::Buffering
|
|
|
24
24
|
|
|
25
25
|
# A buffer which will retain binary encoding.
|
|
26
26
|
class Buffer < String
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
unless String.method_defined?(:append_as_bytes)
|
|
28
|
+
alias_method :_append, :<<
|
|
29
|
+
def append_as_bytes(string)
|
|
30
|
+
if string.encoding == Encoding::BINARY
|
|
31
|
+
_append(string)
|
|
32
|
+
else
|
|
33
|
+
_append(string.b)
|
|
34
|
+
end
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
if string.encoding == BINARY
|
|
37
|
-
super(string)
|
|
38
|
-
else
|
|
39
|
-
super(string.b)
|
|
36
|
+
self
|
|
40
37
|
end
|
|
41
|
-
|
|
42
|
-
return self
|
|
43
38
|
end
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
undef_method :concat
|
|
41
|
+
undef_method :<<
|
|
46
42
|
end
|
|
47
43
|
|
|
48
44
|
##
|
|
@@ -77,7 +73,7 @@ module OpenSSL::Buffering
|
|
|
77
73
|
|
|
78
74
|
def fill_rbuff
|
|
79
75
|
begin
|
|
80
|
-
@rbuffer
|
|
76
|
+
@rbuffer.append_as_bytes(self.sysread(BLOCK_SIZE))
|
|
81
77
|
rescue Errno::EAGAIN
|
|
82
78
|
retry
|
|
83
79
|
rescue EOFError
|
|
@@ -352,22 +348,32 @@ module OpenSSL::Buffering
|
|
|
352
348
|
|
|
353
349
|
def do_write(s)
|
|
354
350
|
@wbuffer = Buffer.new unless defined? @wbuffer
|
|
355
|
-
@wbuffer
|
|
356
|
-
|
|
351
|
+
@wbuffer.append_as_bytes(s)
|
|
352
|
+
|
|
357
353
|
@sync ||= false
|
|
358
|
-
buffer_size = @wbuffer.
|
|
354
|
+
buffer_size = @wbuffer.bytesize
|
|
359
355
|
if @sync or buffer_size > BLOCK_SIZE
|
|
360
356
|
nwrote = 0
|
|
361
357
|
begin
|
|
362
358
|
while nwrote < buffer_size do
|
|
363
359
|
begin
|
|
364
|
-
|
|
360
|
+
chunk = if nwrote > 0
|
|
361
|
+
@wbuffer.byteslice(nwrote, @wbuffer.bytesize)
|
|
362
|
+
else
|
|
363
|
+
@wbuffer
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
nwrote += syswrite(chunk)
|
|
365
367
|
rescue Errno::EAGAIN
|
|
366
368
|
retry
|
|
367
369
|
end
|
|
368
370
|
end
|
|
369
371
|
ensure
|
|
370
|
-
|
|
372
|
+
if nwrote < @wbuffer.bytesize
|
|
373
|
+
@wbuffer[0, nwrote] = ""
|
|
374
|
+
else
|
|
375
|
+
@wbuffer.clear
|
|
376
|
+
end
|
|
371
377
|
end
|
|
372
378
|
end
|
|
373
379
|
end
|
|
@@ -444,10 +450,10 @@ module OpenSSL::Buffering
|
|
|
444
450
|
def puts(*args)
|
|
445
451
|
s = Buffer.new
|
|
446
452
|
if args.empty?
|
|
447
|
-
s
|
|
453
|
+
s.append_as_bytes("\n")
|
|
448
454
|
end
|
|
449
455
|
args.each{|arg|
|
|
450
|
-
s
|
|
456
|
+
s.append_as_bytes(arg.to_s)
|
|
451
457
|
s.sub!(/(?<!\n)\z/, "\n")
|
|
452
458
|
}
|
|
453
459
|
do_write(s)
|
|
@@ -461,7 +467,7 @@ module OpenSSL::Buffering
|
|
|
461
467
|
|
|
462
468
|
def print(*args)
|
|
463
469
|
s = Buffer.new
|
|
464
|
-
args.each{ |arg| s
|
|
470
|
+
args.each{ |arg| s.append_as_bytes(arg.to_s) }
|
|
465
471
|
do_write(s)
|
|
466
472
|
nil
|
|
467
473
|
end
|