Skip to content

Commit 706534a

Browse files
authored
Updates and backports to 4-3-stable (#2829)
* Actions - add Ruby 3.0 and 3.1 * .gitignore - add entry for local use * test_puma_server_ssl.rb - backport fix 888b0213f11 * minissl.c and extconf.rb - backport fixes Fixes from PR's: #2535 #2633 #2642
1 parent 1a3e339 commit 706534a

File tree

5 files changed

+98
-53
lines changed

5 files changed

+98
-53
lines changed

‎.github/workflows/puma.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [ ubuntu-20.04, ubuntu-18.04, macos-10.15, windows-2019 ]
23-
ruby: [ 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, head ]
22+
os: [ ubuntu-20.04, ubuntu-18.04, macos-10.15, windows-2022 ]
23+
ruby: [ 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, head ]
2424
include:
25-
- { os: windows-2019 , ruby: mingw }
25+
- { os: windows-2022 , ruby: ucrt }
2626
exclude:
2727
- { os: ubuntu-20.04 , ruby: 2.2 }
2828
- { os: ubuntu-20.04 , ruby: 2.3 }
2929
- { os: ubuntu-20.04 , ruby: 2.4 }
3030
- { os: ubuntu-20.04 , ruby: 2.6 }
31-
- { os: windows-2019 , ruby: head }
31+
- { os: windows-2022 , ruby: head }
3232

3333
steps:
3434
- name: repo checkout
@@ -40,7 +40,7 @@ jobs:
4040
ruby-version: ${{ matrix.ruby }}
4141
apt-get: ragel
4242
brew: ragel
43-
mingw: _upgrade_ openssl ragel
43+
mingw: openssl ragel
4444

4545
- name: bundle install
4646
shell: pwsh

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pkg
1111
tmp
1212
t/
1313
.rbx/
14+
vendor/
1415
Gemfile.lock
1516
.idea/
1617
/test/test_puma.state

‎ext/puma_http11/extconf.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
# with versions after 1.1.1
2323
have_func "TLS_server_method" , "openssl/ssl.h"
2424
have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
25+
26+
# Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
27+
if Random.respond_to?(:bytes)
28+
$defs.push("-DHAVE_RANDOM_BYTES")
29+
puts "checking for Random.bytes... yes"
30+
else
31+
puts "checking for Random.bytes... no"
32+
end
2533
end
2634
end
2735

‎ext/puma_http11/mini_ssl.c

Lines changed: 82 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,65 @@ ms_conn* engine_alloc(VALUE klass, VALUE* obj) {
6262
return conn;
6363
}
6464

65-
DH *get_dh1024() {
66-
/* `openssl dhparam 1024 -C`
65+
DH *get_dh2048(void) {
66+
/* `openssl dhparam -C 2048`
6767
* -----BEGIN DH PARAMETERS-----
68-
* MIGHAoGBALPwcEv0OstmQCZdfHw0N5r+07lmXMxkpQacy1blwj0LUqC+Divp6pBk
69-
* usTJ9W2/dOYr1X7zi6yXNLp4oLzc/31PUL3D9q8CpGS7vPz5gijKSw9BwCTT5z9+
70-
* KF9v46qw8XqT5HHV87sWFlGQcVFq+pEkA2kPikkKZ/X/CCcpCAV7AgEC
68+
* MIIBCAKCAQEAjmh1uQHdTfxOyxEbKAV30fUfzqMDF/ChPzjfyzl2jcrqQMhrk76o
69+
* 2NPNXqxHwsddMZ1RzvU8/jl+uhRuPWjXCFZbhET4N1vrviZM3VJhV8PPHuiVOACO
70+
* y32jFd+Szx4bo2cXSK83hJ6jRd+0asP1awWjz9/06dFkrILCXMIfQLo0D8rqmppn
71+
* EfDDAwuudCpM9kcDmBRAm9JsKbQ6gzZWjkc5+QWSaQofojIHbjvj3xzguaCJn+oQ
72+
* vHWM+hsAnaOgEwCyeZ3xqs+/5lwSbkE/tqJW98cEZGygBUVo9jxZRZx6KOfjpdrb
73+
* yenO9LJr/qtyrZB31WJbqxI0m0AKTAO8UwIBAg==
7174
* -----END DH PARAMETERS-----
7275
*/
73-
static unsigned char dh1024_p[] = {
74-
0xB3,0xF0,0x70,0x4B,0xF4,0x3A,0xCB,0x66,0x40,0x26,0x5D,0x7C,
75-
0x7C,0x34,0x37,0x9A,0xFE,0xD3,0xB9,0x66,0x5C,0xCC,0x64,0xA5,
76-
0x06,0x9C,0xCB,0x56,0xE5,0xC2,0x3D,0x0B,0x52,0xA0,0xBE,0x0E,
77-
0x2B,0xE9,0xEA,0x90,0x64,0xBA,0xC4,0xC9,0xF5,0x6D,0xBF,0x74,
78-
0xE6,0x2B,0xD5,0x7E,0xF3,0x8B,0xAC,0x97,0x34,0xBA,0x78,0xA0,
79-
0xBC,0xDC,0xFF,0x7D,0x4F,0x50,0xBD,0xC3,0xF6,0xAF,0x02,0xA4,
80-
0x64,0xBB,0xBC,0xFC,0xF9,0x82,0x28,0xCA,0x4B,0x0F,0x41,0xC0,
81-
0x24,0xD3,0xE7,0x3F,0x7E,0x28,0x5F,0x6F,0xE3,0xAA,0xB0,0xF1,
82-
0x7A,0x93,0xE4,0x71,0xD5,0xF3,0xBB,0x16,0x16,0x51,0x90,0x71,
83-
0x51,0x6A,0xFA,0x91,0x24,0x03,0x69,0x0F,0x8A,0x49,0x0A,0x67,
84-
0xF5,0xFF,0x08,0x27,0x29,0x08,0x05,0x7B
76+
static unsigned char dh2048_p[] = {
77+
0x8E, 0x68, 0x75, 0xB9, 0x01, 0xDD, 0x4D, 0xFC, 0x4E, 0xCB,
78+
0x11, 0x1B, 0x28, 0x05, 0x77, 0xD1, 0xF5, 0x1F, 0xCE, 0xA3,
79+
0x03, 0x17, 0xF0, 0xA1, 0x3F, 0x38, 0xDF, 0xCB, 0x39, 0x76,
80+
0x8D, 0xCA, 0xEA, 0x40, 0xC8, 0x6B, 0x93, 0xBE, 0xA8, 0xD8,
81+
0xD3, 0xCD, 0x5E, 0xAC, 0x47, 0xC2, 0xC7, 0x5D, 0x31, 0x9D,
82+
0x51, 0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x7A, 0x28, 0xE7, 0xE3, 0xA5, 0xDA,
100+
0xDB, 0xC9, 0xE9, 0xCE, 0xF4, 0xB2, 0x6B, 0xFE, 0xAB, 0x72,
101+
0xAD, 0x90, 0x77, 0xD5, 0x62, 0x5B, 0xAB, 0x12, 0x34, 0x9B,
102+
0x40, 0x0A, 0x4C, 0x03, 0xBC, 0x53
85103
};
86-
static unsigned char dh1024_g[] = { 0x02 };
104+
static unsigned char dh2048_g[] = { 0x02 };
87105

88106
DH *dh;
107+
#if !(OPENSSL_VERSION_NUMBER < 0x10100005L || defined(LIBRESSL_VERSION_NUMBER))
108+
BIGNUM *p, *g;
109+
#endif
110+
89111
dh = DH_new();
90112

91113
#if OPENSSL_VERSION_NUMBER < 0x10100005L || defined(LIBRESSL_VERSION_NUMBER)
92-
dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
93-
dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL);
114+
dh->p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);
115+
dh->g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);
94116

95117
if ((dh->p == NULL) || (dh->g == NULL)) {
96118
DH_free(dh);
97119
return NULL;
98120
}
99121
#else
100-
BIGNUM *p, *g;
101-
p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
102-
g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL);
122+
p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);
123+
g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);
103124

104125
if (p == NULL || g == NULL || !DH_set0_pqg(dh, p, NULL, g)) {
105126
DH_free(dh);
@@ -139,7 +160,7 @@ static int engine_verify_callback(int preverify_ok, X509_STORE_CTX* ctx) {
139160
}
140161

141162
VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
142-
VALUE obj;
163+
VALUE obj, session_id_bytes;
143164
SSL_CTX* ctx;
144165
SSL* ssl;
145166
int min, ssl_options;
@@ -198,7 +219,7 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
198219
else {
199220
min = TLS1_VERSION;
200221
}
201-
222+
202223
SSL_CTX_set_min_proto_version(ctx, min);
203224

204225
SSL_CTX_set_options(ctx, ssl_options);
@@ -226,7 +247,21 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
226247
SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL@STRENGTH");
227248
}
228249

229-
DH *dh = get_dh1024();
250+
// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
251+
session_id_bytes = rb_funcall(
252+
#ifdef HAVE_RANDOM_BYTES
253+
rb_cRandom,
254+
#else
255+
rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
256+
#endif
257+
rb_intern_const("bytes"),
258+
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));
259+
260+
SSL_CTX_set_session_id_context(ctx,
261+
(unsigned char *) RSTRING_PTR(session_id_bytes),
262+
SSL_MAX_SSL_SESSION_ID_LENGTH);
263+
264+
DH *dh = get_dh2048();
230265
SSL_CTX_set_tmp_dh(ctx, dh);
231266

232267
#if OPENSSL_VERSION_NUMBER < 0x10002000L
@@ -493,27 +528,27 @@ void Init_mini_ssl(VALUE puma) {
493528
#else
494529
rb_define_const(mod, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));
495530
#endif
496-
497-
#if defined(OPENSSL_NO_SSL3) || defined(OPENSSL_NO_SSL3_METHOD)
498-
/* True if SSL3 is not available */
499-
rb_define_const(mod, "OPENSSL_NO_SSL3", Qtrue);
500-
#else
501-
rb_define_const(mod, "OPENSSL_NO_SSL3", Qfalse);
502-
#endif
503-
504-
#if defined(OPENSSL_NO_TLS1) || defined(OPENSSL_NO_TLS1_METHOD)
505-
/* True if TLS1 is not available */
506-
rb_define_const(mod, "OPENSSL_NO_TLS1", Qtrue);
507-
#else
508-
rb_define_const(mod, "OPENSSL_NO_TLS1", Qfalse);
509-
#endif
510-
511-
#if defined(OPENSSL_NO_TLS1_1) || defined(OPENSSL_NO_TLS1_1_METHOD)
512-
/* True if TLS1_1 is not available */
513-
rb_define_const(mod, "OPENSSL_NO_TLS1_1", Qtrue);
514-
#else
515-
rb_define_const(mod, "OPENSSL_NO_TLS1_1", Qfalse);
516-
#endif
531+
532+
#if defined(OPENSSL_NO_SSL3) || defined(OPENSSL_NO_SSL3_METHOD)
533+
/* True if SSL3 is not available */
534+
rb_define_const(mod, "OPENSSL_NO_SSL3", Qtrue);
535+
#else
536+
rb_define_const(mod, "OPENSSL_NO_SSL3", Qfalse);
537+
#endif
538+
539+
#if defined(OPENSSL_NO_TLS1) || defined(OPENSSL_NO_TLS1_METHOD)
540+
/* True if TLS1 is not available */
541+
rb_define_const(mod, "OPENSSL_NO_TLS1", Qtrue);
542+
#else
543+
rb_define_const(mod, "OPENSSL_NO_TLS1", Qfalse);
544+
#endif
545+
546+
#if defined(OPENSSL_NO_TLS1_1) || defined(OPENSSL_NO_TLS1_1_METHOD)
547+
/* True if TLS1_1 is not available */
548+
rb_define_const(mod, "OPENSSL_NO_TLS1_1", Qtrue);
549+
#else
550+
rb_define_const(mod, "OPENSSL_NO_TLS1_1", Qfalse);
551+
#endif
517552

518553
rb_define_singleton_method(mod, "check", noop, 0);
519554

‎test/test_puma_server_ssl.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def test_request_wont_block_thread
9494
ctx = OpenSSL::SSL::SSLContext.new
9595
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
9696
socket = OpenSSL::SSL::SSLSocket.new TCPSocket.new(@host, @port), ctx
97-
socket.write "x"
97+
socket.connect
98+
socket.write "HEAD"
9899
sleep 0.1
99100

100101
# Capture the amount of threads being used after connecting and being idle

0 commit comments

Comments
 (0)