Skip to content

Commit 51d1871

Browse files
committed
Merge branch 'maint-2.2'
* maint-2.2: (43 commits) Ruby/OpenSSL 2.2.1 openssl is ractor-safe Fixed the results of OpenSSL::Timestamp::Response#failure_info Don't redefine #rb_intern over and over again Use rb_intern_const instead of rb_intern in Init functions Remove trailing spaces [ci skip] test/openssl/test_ssl: use TLS 1.2 for finished_messages on LibreSSL Ruby/OpenSSL 2.1.3 ssl: avoid directly storing String object in NPN callback x509store: explicitly call rb_gc_mark() against Store/StoreContext ssl: explicitly call rb_gc_mark() against SSLContext/SSLSocket objects digest: load digest library using Kernel#require pkey: use RSTRING_LENINT() instead of casting to int fix segv in Timestamp::{Request,Response,TokenInfo}.new ts: libressl build fix warning ext/openssl/extconf.rb: require OpenSSL version >= 1.0.1, < 3 .github/workflows: update OpenSSL/LibreSSL versions test: adjust test cases for LibreSSL 3.2.4 ssl: temporary lock string buffer while reading ssl: create a temporary frozen string buffer when writing ...
2 parents e3a4093 + 65e7207 commit 51d1871

File tree

11 files changed

+168
-47
lines changed

11 files changed

+168
-47
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ jobs:
7373
openssl:
7474
- openssl-1.0.2u # EOL
7575
- openssl-1.1.0l # EOL
76-
- openssl-1.1.1j
77-
- libressl-3.1.5
78-
- libressl-3.2.4
76+
- openssl-1.1.1l
77+
- libressl-3.1.5 # EOL
78+
- libressl-3.2.6
79+
- libressl-3.3.4
7980
steps:
8081
- name: repo checkout
8182
uses: actions/checkout@v2

History.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
Version 2.2.1
2+
=============
3+
4+
Merged changes in 2.1.3. Additionally, the following issues are fixed by this
5+
release.
6+
7+
Bug fixes
8+
---------
9+
10+
* Fix crash in `OpenSSL::Timestamp::{Request,Response,TokenInfo}.new` when
11+
invalid arguments are given.
12+
[[GitHub #407]](https://github.com/ruby/openssl/pull/407)
13+
* Fix `OpenSSL::Timestamp::Factory#create_timestamp` with LibreSSL on platforms
14+
where `time_t` has a different size from `long`.
15+
[[GitHub #454]](https://github.com/ruby/openssl/pull/454)
16+
17+
118
Version 2.2.0
219
=============
320

@@ -75,6 +92,42 @@ Notable changes
7592
[[GitHub #297]](https://github.com/ruby/openssl/pull/297)
7693

7794

95+
Version 2.1.3
96+
=============
97+
98+
Bug fixes
99+
---------
100+
101+
* Fix deprecation warnings on Ruby 3.0.
102+
* Add ".include" directive support in `OpenSSL::Config`.
103+
[[GitHub #216]](https://github.com/ruby/openssl/pull/216)
104+
* Fix handling of IPv6 address SANs.
105+
[[GitHub #185]](https://github.com/ruby/openssl/pull/185)
106+
* Hostname verification failure with `OpenSSL::SSL::SSLContext#verify_hostname=`
107+
sets a proper error code.
108+
[[GitHub #350]](https://github.com/ruby/openssl/pull/350)
109+
* Fix crash with `OpenSSL::BN.new(nil, 2)`.
110+
[[Bug #15760]](https://bugs.ruby-lang.org/issues/15760)
111+
* `OpenSSL::SSL::SSLSocket#sys{read,write}` prevent internal string buffers from
112+
being modified by another thread.
113+
[[GitHub #453]](https://github.com/ruby/openssl/pull/453)
114+
* Fix misuse of input record separator in `OpenSSL::Buffering` where it was
115+
for output.
116+
* Fix wrong interger casting in `OpenSSL::PKey::EC#dsa_verify_asn1`.
117+
[[GitHub #460]](https://github.com/ruby/openssl/pull/460)
118+
* `extconf.rb` explicitly checks that OpenSSL's version number is 1.0.1 or
119+
newer but also less than 3.0. Ruby/OpenSSL v2.1.x and v2.2.x will not support
120+
OpenSSL 3.0 API.
121+
[[GitHub #458]](https://github.com/ruby/openssl/pull/458)
122+
* Activate `digest` gem correctly. `digest` library could go into an
123+
inconsistent state if there are multiple versions of `digest` is installed
124+
and `openssl` is `require`d before `digest`.
125+
[[GitHub #463]](https://github.com/ruby/openssl/pull/463)
126+
* Fix GC.compact compatibility.
127+
[[GitHub #464]](https://github.com/ruby/openssl/issues/464)
128+
[[GitHub #465]](https://github.com/ruby/openssl/pull/465)
129+
130+
78131
Version 2.1.2
79132
=============
80133

ext/openssl/ossl_digest.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ ossl_digest_block_length(VALUE self)
313313
void
314314
Init_ossl_digest(void)
315315
{
316-
rb_require("digest");
317-
318316
#if 0
319317
mOSSL = rb_define_module("OpenSSL");
320318
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
@@ -398,6 +396,12 @@ Init_ossl_digest(void)
398396
* digest2 = sha256.digest(data2)
399397
*
400398
*/
399+
400+
/*
401+
* Digest::Class is defined by the digest library. rb_require() cannot be
402+
* used here because it bypasses RubyGems.
403+
*/
404+
rb_funcall(Qnil, rb_intern_const("require"), 1, rb_str_new_cstr("digest"));
401405
cDigest = rb_define_class_under(mOSSL, "Digest", rb_path2class("Digest::Class"));
402406
/* Document-class: OpenSSL::Digest::DigestError
403407
*

ext/openssl/ossl_ssl.c

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ static int ossl_ssl_ex_vcb_idx;
5656
static int ossl_ssl_ex_ptr_idx;
5757
static int ossl_sslctx_ex_ptr_idx;
5858

59+
static void
60+
ossl_sslctx_mark(void *ptr)
61+
{
62+
SSL_CTX *ctx = ptr;
63+
rb_gc_mark((VALUE)SSL_CTX_get_ex_data(ctx, ossl_sslctx_ex_ptr_idx));
64+
}
65+
5966
static void
6067
ossl_sslctx_free(void *ptr)
6168
{
@@ -65,7 +72,7 @@ ossl_sslctx_free(void *ptr)
6572
static const rb_data_type_t ossl_sslctx_type = {
6673
"OpenSSL/SSL/CTX",
6774
{
68-
0, ossl_sslctx_free,
75+
ossl_sslctx_mark, ossl_sslctx_free,
6976
},
7077
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
7178
};
@@ -653,7 +660,7 @@ static int
653660
ssl_npn_advertise_cb(SSL *ssl, const unsigned char **out, unsigned int *outlen,
654661
void *arg)
655662
{
656-
VALUE protocols = (VALUE)arg;
663+
VALUE protocols = rb_attr_get((VALUE)arg, id_npn_protocols_encoded);
657664

658665
*out = (const unsigned char *) RSTRING_PTR(protocols);
659666
*outlen = RSTRING_LENINT(protocols);
@@ -843,7 +850,7 @@ ossl_sslctx_setup(VALUE self)
843850
if (!NIL_P(val)) {
844851
VALUE encoded = ssl_encode_npn_protocols(val);
845852
rb_ivar_set(self, id_npn_protocols_encoded, encoded);
846-
SSL_CTX_set_next_protos_advertised_cb(ctx, ssl_npn_advertise_cb, (void *)encoded);
853+
SSL_CTX_set_next_protos_advertised_cb(ctx, ssl_npn_advertise_cb, (void *)self);
847854
OSSL_Debug("SSL NPN advertise callback added");
848855
}
849856
if (RTEST(rb_attr_get(self, id_i_npn_select_cb))) {
@@ -1433,6 +1440,14 @@ ssl_started(SSL *ssl)
14331440
return SSL_get_fd(ssl) >= 0;
14341441
}
14351442

1443+
static void
1444+
ossl_ssl_mark(void *ptr)
1445+
{
1446+
SSL *ssl = ptr;
1447+
rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx));
1448+
rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_vcb_idx));
1449+
}
1450+
14361451
static void
14371452
ossl_ssl_free(void *ssl)
14381453
{
@@ -1442,7 +1457,7 @@ ossl_ssl_free(void *ssl)
14421457
const rb_data_type_t ossl_ssl_type = {
14431458
"OpenSSL/SSL",
14441459
{
1445-
0, ossl_ssl_free,
1460+
ossl_ssl_mark, ossl_ssl_free,
14461461
},
14471462
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
14481463
};
@@ -1806,26 +1821,36 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
18061821
io = rb_attr_get(self, id_i_io);
18071822
GetOpenFile(io, fptr);
18081823
if (ssl_started(ssl)) {
1809-
for (;;){
1824+
rb_str_locktmp(str);
1825+
for (;;) {
18101826
nread = SSL_read(ssl, RSTRING_PTR(str), ilen);
18111827
switch(ssl_get_error(ssl, nread)){
18121828
case SSL_ERROR_NONE:
1829+
rb_str_unlocktmp(str);
18131830
goto end;
18141831
case SSL_ERROR_ZERO_RETURN:
1832+
rb_str_unlocktmp(str);
18151833
if (no_exception_p(opts)) { return Qnil; }
18161834
rb_eof_error();
18171835
case SSL_ERROR_WANT_WRITE:
1818-
if (no_exception_p(opts)) { return sym_wait_writable; }
1819-
write_would_block(nonblock);
1836+
if (nonblock) {
1837+
rb_str_unlocktmp(str);
1838+
if (no_exception_p(opts)) { return sym_wait_writable; }
1839+
write_would_block(nonblock);
1840+
}
18201841
io_wait_writable(fptr);
18211842
continue;
18221843
case SSL_ERROR_WANT_READ:
1823-
if (no_exception_p(opts)) { return sym_wait_readable; }
1824-
read_would_block(nonblock);
1844+
if (nonblock) {
1845+
rb_str_unlocktmp(str);
1846+
if (no_exception_p(opts)) { return sym_wait_readable; }
1847+
read_would_block(nonblock);
1848+
}
18251849
io_wait_readable(fptr);
18261850
continue;
18271851
case SSL_ERROR_SYSCALL:
18281852
if (!ERR_peek_error()) {
1853+
rb_str_unlocktmp(str);
18291854
if (errno)
18301855
rb_sys_fail(0);
18311856
else {
@@ -1842,6 +1867,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
18421867
}
18431868
/* fall through */
18441869
default:
1870+
rb_str_unlocktmp(str);
18451871
ossl_raise(eSSLError, "SSL_read");
18461872
}
18471873
}
@@ -1912,21 +1938,21 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
19121938
int nwrite = 0;
19131939
rb_io_t *fptr;
19141940
int nonblock = opts != Qfalse;
1915-
VALUE io;
1941+
VALUE tmp, io;
19161942

1917-
StringValue(str);
1943+
tmp = rb_str_new_frozen(StringValue(str));
19181944
GetSSL(self, ssl);
19191945
io = rb_attr_get(self, id_i_io);
19201946
GetOpenFile(io, fptr);
19211947
if (ssl_started(ssl)) {
1922-
for (;;){
1923-
int num = RSTRING_LENINT(str);
1948+
for (;;) {
1949+
int num = RSTRING_LENINT(tmp);
19241950

19251951
/* SSL_write(3ssl) manpage states num == 0 is undefined */
19261952
if (num == 0)
19271953
goto end;
19281954

1929-
nwrite = SSL_write(ssl, RSTRING_PTR(str), num);
1955+
nwrite = SSL_write(ssl, RSTRING_PTR(tmp), num);
19301956
switch(ssl_get_error(ssl, nwrite)){
19311957
case SSL_ERROR_NONE:
19321958
goto end;

ext/openssl/ossl_ts.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ ossl_ts_req_initialize(int argc, VALUE *argv, VALUE self)
211211
in = ossl_obj2bio(&arg);
212212
ts_req = d2i_TS_REQ_bio(in, &ts_req);
213213
BIO_free(in);
214-
if (!ts_req)
214+
if (!ts_req) {
215+
DATA_PTR(self) = NULL;
215216
ossl_raise(eTimestampError, "Error when decoding the timestamp request");
217+
}
216218
DATA_PTR(self) = ts_req;
217219

218220
return self;
@@ -535,8 +537,10 @@ ossl_ts_resp_initialize(VALUE self, VALUE der)
535537
in = ossl_obj2bio(&der);
536538
ts_resp = d2i_TS_RESP_bio(in, &ts_resp);
537539
BIO_free(in);
538-
if (!ts_resp)
540+
if (!ts_resp) {
541+
DATA_PTR(self) = NULL;
539542
ossl_raise(eTimestampError, "Error when decoding the timestamp response");
543+
}
540544
DATA_PTR(self) = ts_resp;
541545

542546
return self;
@@ -874,8 +878,10 @@ ossl_ts_token_info_initialize(VALUE self, VALUE der)
874878
in = ossl_obj2bio(&der);
875879
info = d2i_TS_TST_INFO_bio(in, &info);
876880
BIO_free(in);
877-
if (!info)
881+
if (!info) {
882+
DATA_PTR(self) = NULL;
878883
ossl_raise(eTimestampError, "Error when decoding the timestamp token info");
884+
}
879885
DATA_PTR(self) = info;
880886

881887
return self;
@@ -1077,7 +1083,11 @@ ossl_tsfac_serial_cb(struct TS_resp_ctx *ctx, void *data)
10771083
}
10781084

10791085
static int
1086+
#if !defined(LIBRESSL_VERSION_NUMBER)
10801087
ossl_tsfac_time_cb(struct TS_resp_ctx *ctx, void *data, long *sec, long *usec)
1088+
#else
1089+
ossl_tsfac_time_cb(struct TS_resp_ctx *ctx, void *data, time_t *sec, long *usec)
1090+
#endif
10811091
{
10821092
*sec = *((long *)data);
10831093
*usec = 0;

ext/openssl/ossl_x509store.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ VALUE cX509Store;
112112
VALUE cX509StoreContext;
113113
VALUE eX509StoreError;
114114

115+
static void
116+
ossl_x509store_mark(void *ptr)
117+
{
118+
X509_STORE *store = ptr;
119+
rb_gc_mark((VALUE)X509_STORE_get_ex_data(store, store_ex_verify_cb_idx));
120+
}
121+
115122
static void
116123
ossl_x509store_free(void *ptr)
117124
{
@@ -121,7 +128,7 @@ ossl_x509store_free(void *ptr)
121128
static const rb_data_type_t ossl_x509store_type = {
122129
"OpenSSL/X509/STORE",
123130
{
124-
0, ossl_x509store_free,
131+
ossl_x509store_mark, ossl_x509store_free,
125132
},
126133
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
127134
};
@@ -493,23 +500,16 @@ ossl_x509store_verify(int argc, VALUE *argv, VALUE self)
493500
return result;
494501
}
495502

496-
/*
497-
* Public Functions
498-
*/
499-
static void ossl_x509stctx_free(void*);
500-
501-
502-
static const rb_data_type_t ossl_x509stctx_type = {
503-
"OpenSSL/X509/STORE_CTX",
504-
{
505-
0, ossl_x509stctx_free,
506-
},
507-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
508-
};
509-
510503
/*
511504
* Private functions
512505
*/
506+
static void
507+
ossl_x509stctx_mark(void *ptr)
508+
{
509+
X509_STORE_CTX *ctx = ptr;
510+
rb_gc_mark((VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx));
511+
}
512+
513513
static void
514514
ossl_x509stctx_free(void *ptr)
515515
{
@@ -521,6 +521,14 @@ ossl_x509stctx_free(void *ptr)
521521
X509_STORE_CTX_free(ctx);
522522
}
523523

524+
static const rb_data_type_t ossl_x509stctx_type = {
525+
"OpenSSL/X509/STORE_CTX",
526+
{
527+
ossl_x509stctx_mark, ossl_x509stctx_free,
528+
},
529+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
530+
};
531+
524532
static VALUE
525533
ossl_x509stctx_alloc(VALUE klass)
526534
{

lib/openssl/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module OpenSSL
4-
VERSION = "2.2.0"
4+
VERSION = "2.2.1"
55
end

openssl.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = "openssl"
3-
spec.version = "2.2.0"
3+
spec.version = "2.2.1"
44
spec.authors = ["Martin Bosslet", "SHIBATA Hiroshi", "Zachary Scott", "Kazuki Yamaguchi"]
55
spec.email = ["[email protected]"]
66
spec.summary = %q{OpenSSL provides SSL, TLS and general purpose cryptography.}

0 commit comments

Comments
 (0)