openssl 2.0.0.beta.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of openssl might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/History.md +4 -1
- data/README.md +4 -8
- data/ext/openssl/extconf.rb +0 -6
- data/ext/openssl/ossl.c +27 -88
- data/ext/openssl/ossl.h +3 -39
- data/ext/openssl/ossl_asn1.c +69 -129
- data/ext/openssl/ossl_bio.c +0 -3
- data/ext/openssl/ossl_bn.c +9 -8
- data/ext/openssl/ossl_cipher.c +39 -40
- data/ext/openssl/ossl_digest.c +22 -15
- data/ext/openssl/ossl_engine.c +1 -18
- data/ext/openssl/ossl_ns_spki.c +1 -6
- data/ext/openssl/ossl_pkcs7.c +1 -1
- data/ext/openssl/ossl_pkey.c +75 -32
- data/ext/openssl/ossl_pkey.h +0 -1
- data/ext/openssl/ossl_pkey_dh.c +1 -1
- data/ext/openssl/ossl_pkey_dsa.c +2 -4
- data/ext/openssl/ossl_pkey_ec.c +39 -25
- data/ext/openssl/ossl_pkey_rsa.c +5 -7
- data/ext/openssl/ossl_ssl.c +105 -79
- data/ext/openssl/ossl_ssl_session.c +19 -36
- data/ext/openssl/ossl_x509.h +6 -3
- data/ext/openssl/ossl_x509cert.c +1 -1
- data/ext/openssl/ossl_x509crl.c +5 -24
- data/ext/openssl/ossl_x509name.c +3 -5
- data/ext/openssl/ossl_x509req.c +4 -18
- data/ext/openssl/ossl_x509store.c +83 -25
- data/ext/openssl/ruby_missing.h +0 -9
- data/lib/openssl/buffering.rb +9 -1
- data/lib/openssl/ssl.rb +8 -12
- metadata +17 -17
@@ -108,11 +108,7 @@ int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
|
|
108
108
|
if (a_len != b_len)
|
109
109
|
return 1;
|
110
110
|
|
111
|
-
#if defined(_WIN32)
|
112
|
-
return memcmp(a_sid, b_sid, a_len);
|
113
|
-
#else
|
114
111
|
return CRYPTO_memcmp(a_sid, b_sid, a_len);
|
115
|
-
#endif
|
116
112
|
}
|
117
113
|
#endif
|
118
114
|
|
@@ -141,19 +137,18 @@ static VALUE ossl_ssl_session_eq(VALUE val1, VALUE val2)
|
|
141
137
|
*
|
142
138
|
* Returns the time at which the session was established.
|
143
139
|
*/
|
144
|
-
static VALUE
|
140
|
+
static VALUE
|
141
|
+
ossl_ssl_session_get_time(VALUE self)
|
145
142
|
{
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
GetSSLSession(self, ctx);
|
150
|
-
|
151
|
-
t = SSL_SESSION_get_time(ctx);
|
143
|
+
SSL_SESSION *ctx;
|
144
|
+
long t;
|
152
145
|
|
153
|
-
|
154
|
-
|
146
|
+
GetSSLSession(self, ctx);
|
147
|
+
t = SSL_SESSION_get_time(ctx);
|
148
|
+
if (t == 0)
|
149
|
+
return Qnil;
|
155
150
|
|
156
|
-
|
151
|
+
return rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM(t));
|
157
152
|
}
|
158
153
|
|
159
154
|
/*
|
@@ -164,16 +159,16 @@ static VALUE ossl_ssl_session_get_time(VALUE self)
|
|
164
159
|
* established time.
|
165
160
|
*
|
166
161
|
*/
|
167
|
-
static VALUE
|
162
|
+
static VALUE
|
163
|
+
ossl_ssl_session_get_timeout(VALUE self)
|
168
164
|
{
|
169
|
-
|
170
|
-
|
165
|
+
SSL_SESSION *ctx;
|
166
|
+
long t;
|
171
167
|
|
172
|
-
|
173
|
-
|
174
|
-
t = SSL_SESSION_get_timeout(ctx);
|
168
|
+
GetSSLSession(self, ctx);
|
169
|
+
t = SSL_SESSION_get_timeout(ctx);
|
175
170
|
|
176
|
-
|
171
|
+
return LONG2NUM(t);
|
177
172
|
}
|
178
173
|
|
179
174
|
/*
|
@@ -270,9 +265,6 @@ static VALUE ossl_ssl_session_to_pem(VALUE self)
|
|
270
265
|
{
|
271
266
|
SSL_SESSION *ctx;
|
272
267
|
BIO *out;
|
273
|
-
BUF_MEM *buf;
|
274
|
-
VALUE str;
|
275
|
-
int i;
|
276
268
|
|
277
269
|
GetSSLSession(self, ctx);
|
278
270
|
|
@@ -280,16 +272,13 @@ static VALUE ossl_ssl_session_to_pem(VALUE self)
|
|
280
272
|
ossl_raise(eSSLSession, "BIO_s_mem()");
|
281
273
|
}
|
282
274
|
|
283
|
-
if (!
|
275
|
+
if (!PEM_write_bio_SSL_SESSION(out, ctx)) {
|
284
276
|
BIO_free(out);
|
285
277
|
ossl_raise(eSSLSession, "SSL_SESSION_print()");
|
286
278
|
}
|
287
279
|
|
288
|
-
BIO_get_mem_ptr(out, &buf);
|
289
|
-
str = rb_str_new(buf->data, buf->length);
|
290
|
-
BIO_free(out);
|
291
280
|
|
292
|
-
return
|
281
|
+
return ossl_membio2str(out);
|
293
282
|
}
|
294
283
|
|
295
284
|
|
@@ -303,8 +292,6 @@ static VALUE ossl_ssl_session_to_text(VALUE self)
|
|
303
292
|
{
|
304
293
|
SSL_SESSION *ctx;
|
305
294
|
BIO *out;
|
306
|
-
BUF_MEM *buf;
|
307
|
-
VALUE str;
|
308
295
|
|
309
296
|
GetSSLSession(self, ctx);
|
310
297
|
|
@@ -317,11 +304,7 @@ static VALUE ossl_ssl_session_to_text(VALUE self)
|
|
317
304
|
ossl_raise(eSSLSession, "SSL_SESSION_print()");
|
318
305
|
}
|
319
306
|
|
320
|
-
|
321
|
-
str = rb_str_new(buf->data, buf->length);
|
322
|
-
BIO_free(out);
|
323
|
-
|
324
|
-
return str;
|
307
|
+
return ossl_membio2str(out);
|
325
308
|
}
|
326
309
|
|
327
310
|
|
data/ext/openssl/ossl_x509.h
CHANGED
@@ -110,10 +110,13 @@ VALUE ossl_x509store_new(X509_STORE *);
|
|
110
110
|
X509_STORE *GetX509StorePtr(VALUE);
|
111
111
|
X509_STORE *DupX509StorePtr(VALUE);
|
112
112
|
|
113
|
-
VALUE ossl_x509stctx_new(X509_STORE_CTX *);
|
114
|
-
VALUE ossl_x509stctx_clear_ptr(VALUE);
|
115
113
|
X509_STORE_CTX *GetX509StCtxtPtr(VALUE);
|
116
|
-
|
117
114
|
void Init_ossl_x509store(void);
|
118
115
|
|
116
|
+
/*
|
117
|
+
* Calls the verify callback Proc (the first parameter) with given pre-verify
|
118
|
+
* result and the X509_STORE_CTX.
|
119
|
+
*/
|
120
|
+
int ossl_verify_cb_call(VALUE, int, X509_STORE_CTX *);
|
121
|
+
|
119
122
|
#endif /* _OSSL_X509_H_ */
|
data/ext/openssl/ossl_x509cert.c
CHANGED
@@ -624,7 +624,7 @@ ossl_x509_check_private_key(VALUE self, VALUE key)
|
|
624
624
|
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
625
625
|
GetX509(self, x509);
|
626
626
|
if (!X509_check_private_key(x509, pkey)) {
|
627
|
-
|
627
|
+
ossl_clear_error();
|
628
628
|
return Qfalse;
|
629
629
|
}
|
630
630
|
|
data/ext/openssl/ossl_x509crl.c
CHANGED
@@ -182,8 +182,6 @@ ossl_x509crl_get_signature_algorithm(VALUE self)
|
|
182
182
|
X509_CRL *crl;
|
183
183
|
const X509_ALGOR *alg;
|
184
184
|
BIO *out;
|
185
|
-
BUF_MEM *buf;
|
186
|
-
VALUE str;
|
187
185
|
|
188
186
|
GetX509CRL(self, crl);
|
189
187
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
@@ -194,10 +192,8 @@ ossl_x509crl_get_signature_algorithm(VALUE self)
|
|
194
192
|
BIO_free(out);
|
195
193
|
ossl_raise(eX509CRLError, NULL);
|
196
194
|
}
|
197
|
-
|
198
|
-
|
199
|
-
BIO_free(out);
|
200
|
-
return str;
|
195
|
+
|
196
|
+
return ossl_membio2str(out);
|
201
197
|
}
|
202
198
|
|
203
199
|
static VALUE
|
@@ -388,8 +384,6 @@ ossl_x509crl_to_der(VALUE self)
|
|
388
384
|
{
|
389
385
|
X509_CRL *crl;
|
390
386
|
BIO *out;
|
391
|
-
BUF_MEM *buf;
|
392
|
-
VALUE str;
|
393
387
|
|
394
388
|
GetX509CRL(self, crl);
|
395
389
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
@@ -399,11 +393,8 @@ ossl_x509crl_to_der(VALUE self)
|
|
399
393
|
BIO_free(out);
|
400
394
|
ossl_raise(eX509CRLError, NULL);
|
401
395
|
}
|
402
|
-
BIO_get_mem_ptr(out, &buf);
|
403
|
-
str = rb_str_new(buf->data, buf->length);
|
404
|
-
BIO_free(out);
|
405
396
|
|
406
|
-
return
|
397
|
+
return ossl_membio2str(out);
|
407
398
|
}
|
408
399
|
|
409
400
|
static VALUE
|
@@ -411,8 +402,6 @@ ossl_x509crl_to_pem(VALUE self)
|
|
411
402
|
{
|
412
403
|
X509_CRL *crl;
|
413
404
|
BIO *out;
|
414
|
-
BUF_MEM *buf;
|
415
|
-
VALUE str;
|
416
405
|
|
417
406
|
GetX509CRL(self, crl);
|
418
407
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
@@ -422,11 +411,8 @@ ossl_x509crl_to_pem(VALUE self)
|
|
422
411
|
BIO_free(out);
|
423
412
|
ossl_raise(eX509CRLError, NULL);
|
424
413
|
}
|
425
|
-
BIO_get_mem_ptr(out, &buf);
|
426
|
-
str = rb_str_new(buf->data, buf->length);
|
427
|
-
BIO_free(out);
|
428
414
|
|
429
|
-
return
|
415
|
+
return ossl_membio2str(out);
|
430
416
|
}
|
431
417
|
|
432
418
|
static VALUE
|
@@ -434,8 +420,6 @@ ossl_x509crl_to_text(VALUE self)
|
|
434
420
|
{
|
435
421
|
X509_CRL *crl;
|
436
422
|
BIO *out;
|
437
|
-
BUF_MEM *buf;
|
438
|
-
VALUE str;
|
439
423
|
|
440
424
|
GetX509CRL(self, crl);
|
441
425
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
@@ -445,11 +429,8 @@ ossl_x509crl_to_text(VALUE self)
|
|
445
429
|
BIO_free(out);
|
446
430
|
ossl_raise(eX509CRLError, NULL);
|
447
431
|
}
|
448
|
-
BIO_get_mem_ptr(out, &buf);
|
449
|
-
str = rb_str_new(buf->data, buf->length);
|
450
|
-
BIO_free(out);
|
451
432
|
|
452
|
-
return
|
433
|
+
return ossl_membio2str(out);
|
453
434
|
}
|
454
435
|
|
455
436
|
/*
|
data/ext/openssl/ossl_x509name.c
CHANGED
@@ -372,12 +372,10 @@ ossl_x509name_cmp(VALUE self, VALUE other)
|
|
372
372
|
static VALUE
|
373
373
|
ossl_x509name_eql(VALUE self, VALUE other)
|
374
374
|
{
|
375
|
-
|
376
|
-
|
377
|
-
if(CLASS_OF(other) != cX509Name) return Qfalse;
|
378
|
-
result = ossl_x509name_cmp0(self, other);
|
375
|
+
if (!rb_obj_is_kind_of(other, cX509Name))
|
376
|
+
return Qfalse;
|
379
377
|
|
380
|
-
return (
|
378
|
+
return ossl_x509name_cmp0(self, other) ? Qtrue : Qfalse;
|
381
379
|
}
|
382
380
|
|
383
381
|
/*
|
data/ext/openssl/ossl_x509req.c
CHANGED
@@ -160,8 +160,6 @@ ossl_x509req_to_pem(VALUE self)
|
|
160
160
|
{
|
161
161
|
X509_REQ *req;
|
162
162
|
BIO *out;
|
163
|
-
BUF_MEM *buf;
|
164
|
-
VALUE str;
|
165
163
|
|
166
164
|
GetX509Req(self, req);
|
167
165
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
@@ -171,11 +169,8 @@ ossl_x509req_to_pem(VALUE self)
|
|
171
169
|
BIO_free(out);
|
172
170
|
ossl_raise(eX509ReqError, NULL);
|
173
171
|
}
|
174
|
-
BIO_get_mem_ptr(out, &buf);
|
175
|
-
str = rb_str_new(buf->data, buf->length);
|
176
|
-
BIO_free(out);
|
177
172
|
|
178
|
-
return
|
173
|
+
return ossl_membio2str(out);
|
179
174
|
}
|
180
175
|
|
181
176
|
static VALUE
|
@@ -203,8 +198,6 @@ ossl_x509req_to_text(VALUE self)
|
|
203
198
|
{
|
204
199
|
X509_REQ *req;
|
205
200
|
BIO *out;
|
206
|
-
BUF_MEM *buf;
|
207
|
-
VALUE str;
|
208
201
|
|
209
202
|
GetX509Req(self, req);
|
210
203
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
@@ -214,11 +207,8 @@ ossl_x509req_to_text(VALUE self)
|
|
214
207
|
BIO_free(out);
|
215
208
|
ossl_raise(eX509ReqError, NULL);
|
216
209
|
}
|
217
|
-
BIO_get_mem_ptr(out, &buf);
|
218
|
-
str = rb_str_new(buf->data, buf->length);
|
219
|
-
BIO_free(out);
|
220
210
|
|
221
|
-
return
|
211
|
+
return ossl_membio2str(out);
|
222
212
|
}
|
223
213
|
|
224
214
|
#if 0
|
@@ -304,8 +294,6 @@ ossl_x509req_get_signature_algorithm(VALUE self)
|
|
304
294
|
X509_REQ *req;
|
305
295
|
const X509_ALGOR *alg;
|
306
296
|
BIO *out;
|
307
|
-
BUF_MEM *buf;
|
308
|
-
VALUE str;
|
309
297
|
|
310
298
|
GetX509Req(self, req);
|
311
299
|
|
@@ -317,10 +305,8 @@ ossl_x509req_get_signature_algorithm(VALUE self)
|
|
317
305
|
BIO_free(out);
|
318
306
|
ossl_raise(eX509ReqError, NULL);
|
319
307
|
}
|
320
|
-
|
321
|
-
|
322
|
-
BIO_free(out);
|
323
|
-
return str;
|
308
|
+
|
309
|
+
return ossl_membio2str(out);
|
324
310
|
}
|
325
311
|
|
326
312
|
static VALUE
|
@@ -47,6 +47,65 @@
|
|
47
47
|
GetX509Store((obj), (ctx)); \
|
48
48
|
} while (0)
|
49
49
|
|
50
|
+
/*
|
51
|
+
* Verify callback stuff
|
52
|
+
*/
|
53
|
+
static int stctx_ex_verify_cb_idx, store_ex_verify_cb_idx;
|
54
|
+
static VALUE ossl_x509stctx_new(X509_STORE_CTX *);
|
55
|
+
|
56
|
+
struct ossl_verify_cb_args {
|
57
|
+
VALUE proc;
|
58
|
+
VALUE preverify_ok;
|
59
|
+
VALUE store_ctx;
|
60
|
+
};
|
61
|
+
|
62
|
+
static VALUE
|
63
|
+
call_verify_cb_proc(struct ossl_verify_cb_args *args)
|
64
|
+
{
|
65
|
+
return rb_funcall(args->proc, rb_intern("call"), 2,
|
66
|
+
args->preverify_ok, args->store_ctx);
|
67
|
+
}
|
68
|
+
|
69
|
+
int
|
70
|
+
ossl_verify_cb_call(VALUE proc, int ok, X509_STORE_CTX *ctx)
|
71
|
+
{
|
72
|
+
VALUE rctx, ret;
|
73
|
+
struct ossl_verify_cb_args args;
|
74
|
+
int state;
|
75
|
+
|
76
|
+
if (NIL_P(proc))
|
77
|
+
return ok;
|
78
|
+
|
79
|
+
ret = Qfalse;
|
80
|
+
rctx = rb_protect((VALUE(*)(VALUE))ossl_x509stctx_new, (VALUE)ctx, &state);
|
81
|
+
if (state) {
|
82
|
+
rb_set_errinfo(Qnil);
|
83
|
+
rb_warn("StoreContext initialization failure");
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
args.proc = proc;
|
87
|
+
args.preverify_ok = ok ? Qtrue : Qfalse;
|
88
|
+
args.store_ctx = rctx;
|
89
|
+
ret = rb_protect((VALUE(*)(VALUE))call_verify_cb_proc, (VALUE)&args, &state);
|
90
|
+
if (state) {
|
91
|
+
rb_set_errinfo(Qnil);
|
92
|
+
rb_warn("exception in verify_callback is ignored");
|
93
|
+
}
|
94
|
+
RTYPEDDATA_DATA(rctx) = NULL;
|
95
|
+
}
|
96
|
+
if (ret == Qtrue) {
|
97
|
+
X509_STORE_CTX_set_error(ctx, X509_V_OK);
|
98
|
+
ok = 1;
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
if (X509_STORE_CTX_get_error(ctx) == X509_V_OK)
|
102
|
+
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REJECTED);
|
103
|
+
ok = 0;
|
104
|
+
}
|
105
|
+
|
106
|
+
return ok;
|
107
|
+
}
|
108
|
+
|
50
109
|
/*
|
51
110
|
* Classes
|
52
111
|
*/
|
@@ -111,9 +170,10 @@ x509store_verify_cb(int ok, X509_STORE_CTX *ctx)
|
|
111
170
|
{
|
112
171
|
VALUE proc;
|
113
172
|
|
114
|
-
proc = (VALUE)X509_STORE_CTX_get_ex_data(ctx,
|
173
|
+
proc = (VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx);
|
115
174
|
if (!proc)
|
116
|
-
proc = (VALUE)X509_STORE_get_ex_data(X509_STORE_CTX_get0_store(ctx),
|
175
|
+
proc = (VALUE)X509_STORE_get_ex_data(X509_STORE_CTX_get0_store(ctx),
|
176
|
+
store_ex_verify_cb_idx);
|
117
177
|
if (!proc)
|
118
178
|
return ok;
|
119
179
|
|
@@ -144,7 +204,7 @@ ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
|
|
144
204
|
X509_STORE *store;
|
145
205
|
|
146
206
|
GetX509Store(self, store);
|
147
|
-
X509_STORE_set_ex_data(store,
|
207
|
+
X509_STORE_set_ex_data(store, store_ex_verify_cb_idx, (void *)cb);
|
148
208
|
rb_iv_set(self, "@verify_callback", cb);
|
149
209
|
|
150
210
|
return cb;
|
@@ -432,27 +492,6 @@ static const rb_data_type_t ossl_x509stctx_type = {
|
|
432
492
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
433
493
|
};
|
434
494
|
|
435
|
-
|
436
|
-
VALUE
|
437
|
-
ossl_x509stctx_new(X509_STORE_CTX *ctx)
|
438
|
-
{
|
439
|
-
VALUE obj;
|
440
|
-
|
441
|
-
obj = NewX509StCtx(cX509StoreContext);
|
442
|
-
SetX509StCtx(obj, ctx);
|
443
|
-
|
444
|
-
return obj;
|
445
|
-
}
|
446
|
-
|
447
|
-
VALUE
|
448
|
-
ossl_x509stctx_clear_ptr(VALUE obj)
|
449
|
-
{
|
450
|
-
OSSL_Check_Kind(obj, cX509StoreContext);
|
451
|
-
RDATA(obj)->data = NULL;
|
452
|
-
|
453
|
-
return obj;
|
454
|
-
}
|
455
|
-
|
456
495
|
/*
|
457
496
|
* Private functions
|
458
497
|
*/
|
@@ -482,6 +521,17 @@ ossl_x509stctx_alloc(VALUE klass)
|
|
482
521
|
return obj;
|
483
522
|
}
|
484
523
|
|
524
|
+
static VALUE
|
525
|
+
ossl_x509stctx_new(X509_STORE_CTX *ctx)
|
526
|
+
{
|
527
|
+
VALUE obj;
|
528
|
+
|
529
|
+
obj = NewX509StCtx(cX509StoreContext);
|
530
|
+
SetX509StCtx(obj, ctx);
|
531
|
+
|
532
|
+
return obj;
|
533
|
+
}
|
534
|
+
|
485
535
|
static VALUE ossl_x509stctx_set_flags(VALUE, VALUE);
|
486
536
|
static VALUE ossl_x509stctx_set_purpose(VALUE, VALUE);
|
487
537
|
static VALUE ossl_x509stctx_set_trust(VALUE, VALUE);
|
@@ -527,7 +577,7 @@ ossl_x509stctx_verify(VALUE self)
|
|
527
577
|
X509_STORE_CTX *ctx;
|
528
578
|
|
529
579
|
GetX509StCtx(self, ctx);
|
530
|
-
X509_STORE_CTX_set_ex_data(ctx,
|
580
|
+
X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx,
|
531
581
|
(void *)rb_iv_get(self, "@verify_callback"));
|
532
582
|
|
533
583
|
switch (X509_verify_cert(ctx)) {
|
@@ -747,6 +797,14 @@ Init_ossl_x509store(void)
|
|
747
797
|
mX509 = rb_define_module_under(mOSSL, "X509");
|
748
798
|
#endif
|
749
799
|
|
800
|
+
/* Register ext_data slot for verify callback Proc */
|
801
|
+
stctx_ex_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, (void *)"stctx_ex_verify_cb_idx", 0, 0, 0);
|
802
|
+
if (stctx_ex_verify_cb_idx < 0)
|
803
|
+
ossl_raise(eOSSLError, "X509_STORE_CTX_get_ex_new_index");
|
804
|
+
store_ex_verify_cb_idx = X509_STORE_get_ex_new_index(0, (void *)"store_ex_verify_cb_idx", 0, 0, 0);
|
805
|
+
if (store_ex_verify_cb_idx < 0)
|
806
|
+
ossl_raise(eOSSLError, "X509_STORE_get_ex_new_index");
|
807
|
+
|
750
808
|
eX509StoreError = rb_define_class_under(mX509, "StoreError", eOSSLError);
|
751
809
|
|
752
810
|
/* Document-class: OpenSSL::X509::Store
|