puma 5.0.4 → 5.6.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puma might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.md +322 -48
- data/LICENSE +0 -0
- data/README.md +95 -24
- data/bin/puma-wild +0 -0
- data/docs/architecture.md +57 -20
- data/docs/compile_options.md +21 -0
- data/docs/deployment.md +53 -67
- data/docs/fork_worker.md +2 -0
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/jungle/README.md +0 -0
- data/docs/jungle/rc.d/README.md +1 -1
- data/docs/jungle/rc.d/puma.conf +0 -0
- data/docs/kubernetes.md +66 -0
- data/docs/nginx.md +0 -0
- data/docs/plugins.md +15 -15
- data/docs/rails_dev_mode.md +28 -0
- data/docs/restart.md +7 -7
- data/docs/signals.md +11 -10
- data/docs/stats.md +142 -0
- data/docs/systemd.md +85 -66
- data/ext/puma_http11/PumaHttp11Service.java +0 -0
- data/ext/puma_http11/ext_help.h +0 -0
- data/ext/puma_http11/extconf.rb +42 -6
- data/ext/puma_http11/http11_parser.c +68 -57
- data/ext/puma_http11/http11_parser.h +1 -1
- data/ext/puma_http11/http11_parser.java.rl +1 -1
- data/ext/puma_http11/http11_parser.rl +1 -1
- data/ext/puma_http11/http11_parser_common.rl +1 -1
- data/ext/puma_http11/mini_ssl.c +226 -88
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +0 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +0 -0
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +51 -51
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +28 -43
- data/ext/puma_http11/puma_http11.c +9 -3
- data/lib/puma/app/status.rb +4 -7
- data/lib/puma/binder.rb +138 -49
- data/lib/puma/cli.rb +18 -4
- data/lib/puma/client.rb +113 -31
- data/lib/puma/cluster/worker.rb +22 -19
- data/lib/puma/cluster/worker_handle.rb +13 -2
- data/lib/puma/cluster.rb +75 -33
- data/lib/puma/commonlogger.rb +0 -0
- data/lib/puma/configuration.rb +21 -2
- data/lib/puma/const.rb +17 -8
- data/lib/puma/control_cli.rb +76 -71
- data/lib/puma/detect.rb +19 -9
- data/lib/puma/dsl.rb +225 -31
- data/lib/puma/error_logger.rb +12 -5
- data/lib/puma/events.rb +18 -3
- data/lib/puma/io_buffer.rb +0 -0
- data/lib/puma/jruby_restart.rb +0 -0
- data/lib/puma/json_serialization.rb +96 -0
- data/lib/puma/launcher.rb +56 -7
- data/lib/puma/minissl/context_builder.rb +14 -6
- data/lib/puma/minissl.rb +72 -40
- data/lib/puma/null_io.rb +12 -0
- data/lib/puma/plugin/tmp_restart.rb +0 -0
- data/lib/puma/plugin.rb +2 -2
- data/lib/puma/queue_close.rb +7 -7
- data/lib/puma/rack/builder.rb +1 -1
- data/lib/puma/rack/urlmap.rb +0 -0
- data/lib/puma/rack_default.rb +0 -0
- data/lib/puma/reactor.rb +19 -12
- data/lib/puma/request.rb +55 -21
- data/lib/puma/runner.rb +39 -13
- data/lib/puma/server.rb +78 -142
- data/lib/puma/single.rb +0 -0
- data/lib/puma/state_file.rb +45 -9
- data/lib/puma/systemd.rb +46 -0
- data/lib/puma/thread_pool.rb +11 -8
- data/lib/puma/util.rb +8 -1
- data/lib/puma.rb +36 -10
- data/lib/rack/handler/puma.rb +1 -0
- data/tools/Dockerfile +1 -1
- data/tools/trickletest.rb +0 -0
- metadata +15 -9
data/ext/puma_http11/mini_ssl.c
CHANGED
@@ -28,6 +28,8 @@ typedef struct {
|
|
28
28
|
int bytes;
|
29
29
|
} ms_cert_buf;
|
30
30
|
|
31
|
+
VALUE eError;
|
32
|
+
|
31
33
|
void engine_free(void *ptr) {
|
32
34
|
ms_conn *conn = ptr;
|
33
35
|
ms_cert_buf* cert_buf = (ms_cert_buf*)SSL_get_app_data(conn->ssl);
|
@@ -47,61 +49,66 @@ const rb_data_type_t engine_data_type = {
|
|
47
49
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
48
50
|
};
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
*obj = TypedData_Make_Struct(klass, ms_conn, &engine_data_type, conn);
|
54
|
-
|
55
|
-
conn->read = BIO_new(BIO_s_mem());
|
56
|
-
BIO_set_nbio(conn->read, 1);
|
57
|
-
|
58
|
-
conn->write = BIO_new(BIO_s_mem());
|
59
|
-
BIO_set_nbio(conn->write, 1);
|
60
|
-
|
61
|
-
conn->ssl = 0;
|
62
|
-
conn->ctx = 0;
|
63
|
-
|
64
|
-
return conn;
|
65
|
-
}
|
66
|
-
|
67
|
-
DH *get_dh1024() {
|
68
|
-
/* `openssl dhparam 1024 -C`
|
52
|
+
#ifndef HAVE_SSL_GET1_PEER_CERTIFICATE
|
53
|
+
DH *get_dh2048(void) {
|
54
|
+
/* `openssl dhparam -C 2048`
|
69
55
|
* -----BEGIN DH PARAMETERS-----
|
70
|
-
*
|
71
|
-
*
|
72
|
-
*
|
56
|
+
* MIIBCAKCAQEAjmh1uQHdTfxOyxEbKAV30fUfzqMDF/ChPzjfyzl2jcrqQMhrk76o
|
57
|
+
* 2NPNXqxHwsddMZ1RzvU8/jl+uhRuPWjXCFZbhET4N1vrviZM3VJhV8PPHuiVOACO
|
58
|
+
* y32jFd+Szx4bo2cXSK83hJ6jRd+0asP1awWjz9/06dFkrILCXMIfQLo0D8rqmppn
|
59
|
+
* EfDDAwuudCpM9kcDmBRAm9JsKbQ6gzZWjkc5+QWSaQofojIHbjvj3xzguaCJn+oQ
|
60
|
+
* vHWM+hsAnaOgEwCyeZ3xqs+/5lwSbkE/tqJW98cEZGygBUVo9jxZRZx6KOfjpdrb
|
61
|
+
* yenO9LJr/qtyrZB31WJbqxI0m0AKTAO8UwIBAg==
|
73
62
|
* -----END DH PARAMETERS-----
|
74
63
|
*/
|
75
|
-
static unsigned char
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
64
|
+
static unsigned char dh2048_p[] = {
|
65
|
+
0x8E, 0x68, 0x75, 0xB9, 0x01, 0xDD, 0x4D, 0xFC, 0x4E, 0xCB,
|
66
|
+
0x11, 0x1B, 0x28, 0x05, 0x77, 0xD1, 0xF5, 0x1F, 0xCE, 0xA3,
|
67
|
+
0x03, 0x17, 0xF0, 0xA1, 0x3F, 0x38, 0xDF, 0xCB, 0x39, 0x76,
|
68
|
+
0x8D, 0xCA, 0xEA, 0x40, 0xC8, 0x6B, 0x93, 0xBE, 0xA8, 0xD8,
|
69
|
+
0xD3, 0xCD, 0x5E, 0xAC, 0x47, 0xC2, 0xC7, 0x5D, 0x31, 0x9D,
|
70
|
+
0x51, 0xCE, 0xF5, 0x3C, 0xFE, 0x39, 0x7E, 0xBA, 0x14, 0x6E,
|
71
|
+
0x3D, 0x68, 0xD7, 0x08, 0x56, 0x5B, 0x84, 0x44, 0xF8, 0x37,
|
72
|
+
0x5B, 0xEB, 0xBE, 0x26, 0x4C, 0xDD, 0x52, 0x61, 0x57, 0xC3,
|
73
|
+
0xCF, 0x1E, 0xE8, 0x95, 0x38, 0x00, 0x8E, 0xCB, 0x7D, 0xA3,
|
74
|
+
0x15, 0xDF, 0x92, 0xCF, 0x1E, 0x1B, 0xA3, 0x67, 0x17, 0x48,
|
75
|
+
0xAF, 0x37, 0x84, 0x9E, 0xA3, 0x45, 0xDF, 0xB4, 0x6A, 0xC3,
|
76
|
+
0xF5, 0x6B, 0x05, 0xA3, 0xCF, 0xDF, 0xF4, 0xE9, 0xD1, 0x64,
|
77
|
+
0xAC, 0x82, 0xC2, 0x5C, 0xC2, 0x1F, 0x40, 0xBA, 0x34, 0x0F,
|
78
|
+
0xCA, 0xEA, 0x9A, 0x9A, 0x67, 0x11, 0xF0, 0xC3, 0x03, 0x0B,
|
79
|
+
0xAE, 0x74, 0x2A, 0x4C, 0xF6, 0x47, 0x03, 0x98, 0x14, 0x40,
|
80
|
+
0x9B, 0xD2, 0x6C, 0x29, 0xB4, 0x3A, 0x83, 0x36, 0x56, 0x8E,
|
81
|
+
0x47, 0x39, 0xF9, 0x05, 0x92, 0x69, 0x0A, 0x1F, 0xA2, 0x32,
|
82
|
+
0x07, 0x6E, 0x3B, 0xE3, 0xDF, 0x1C, 0xE0, 0xB9, 0xA0, 0x89,
|
83
|
+
0x9F, 0xEA, 0x10, 0xBC, 0x75, 0x8C, 0xFA, 0x1B, 0x00, 0x9D,
|
84
|
+
0xA3, 0xA0, 0x13, 0x00, 0xB2, 0x79, 0x9D, 0xF1, 0xAA, 0xCF,
|
85
|
+
0xBF, 0xE6, 0x5C, 0x12, 0x6E, 0x41, 0x3F, 0xB6, 0xA2, 0x56,
|
86
|
+
0xF7, 0xC7, 0x04, 0x64, 0x6C, 0xA0, 0x05, 0x45, 0x68, 0xF6,
|
87
|
+
0x3C, 0x59, 0x45, 0x9C, 0x7A, 0x28, 0xE7, 0xE3, 0xA5, 0xDA,
|
88
|
+
0xDB, 0xC9, 0xE9, 0xCE, 0xF4, 0xB2, 0x6B, 0xFE, 0xAB, 0x72,
|
89
|
+
0xAD, 0x90, 0x77, 0xD5, 0x62, 0x5B, 0xAB, 0x12, 0x34, 0x9B,
|
90
|
+
0x40, 0x0A, 0x4C, 0x03, 0xBC, 0x53
|
87
91
|
};
|
88
|
-
static unsigned char
|
92
|
+
static unsigned char dh2048_g[] = { 0x02 };
|
89
93
|
|
90
94
|
DH *dh;
|
95
|
+
#if !(OPENSSL_VERSION_NUMBER < 0x10100005L || defined(LIBRESSL_VERSION_NUMBER))
|
96
|
+
BIGNUM *p, *g;
|
97
|
+
#endif
|
98
|
+
|
91
99
|
dh = DH_new();
|
92
100
|
|
93
101
|
#if OPENSSL_VERSION_NUMBER < 0x10100005L || defined(LIBRESSL_VERSION_NUMBER)
|
94
|
-
dh->p = BN_bin2bn(
|
95
|
-
dh->g = BN_bin2bn(
|
102
|
+
dh->p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);
|
103
|
+
dh->g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);
|
96
104
|
|
97
105
|
if ((dh->p == NULL) || (dh->g == NULL)) {
|
98
106
|
DH_free(dh);
|
99
107
|
return NULL;
|
100
108
|
}
|
101
109
|
#else
|
102
|
-
|
103
|
-
|
104
|
-
g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL);
|
110
|
+
p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);
|
111
|
+
g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);
|
105
112
|
|
106
113
|
if (p == NULL || g == NULL || !DH_set0_pqg(dh, p, NULL, g)) {
|
107
114
|
DH_free(dh);
|
@@ -113,6 +120,38 @@ DH *get_dh1024() {
|
|
113
120
|
|
114
121
|
return dh;
|
115
122
|
}
|
123
|
+
#endif
|
124
|
+
|
125
|
+
static void
|
126
|
+
sslctx_free(void *ptr) {
|
127
|
+
SSL_CTX *ctx = ptr;
|
128
|
+
SSL_CTX_free(ctx);
|
129
|
+
}
|
130
|
+
|
131
|
+
static const rb_data_type_t sslctx_type = {
|
132
|
+
"MiniSSL/SSLContext",
|
133
|
+
{
|
134
|
+
0, sslctx_free,
|
135
|
+
},
|
136
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
137
|
+
};
|
138
|
+
|
139
|
+
ms_conn* engine_alloc(VALUE klass, VALUE* obj) {
|
140
|
+
ms_conn* conn;
|
141
|
+
|
142
|
+
*obj = TypedData_Make_Struct(klass, ms_conn, &engine_data_type, conn);
|
143
|
+
|
144
|
+
conn->read = BIO_new(BIO_s_mem());
|
145
|
+
BIO_set_nbio(conn->read, 1);
|
146
|
+
|
147
|
+
conn->write = BIO_new(BIO_s_mem());
|
148
|
+
BIO_set_nbio(conn->write, 1);
|
149
|
+
|
150
|
+
conn->ssl = 0;
|
151
|
+
conn->ctx = 0;
|
152
|
+
|
153
|
+
return conn;
|
154
|
+
}
|
116
155
|
|
117
156
|
static int engine_verify_callback(int preverify_ok, X509_STORE_CTX* ctx) {
|
118
157
|
X509* err_cert;
|
@@ -140,48 +179,102 @@ static int engine_verify_callback(int preverify_ok, X509_STORE_CTX* ctx) {
|
|
140
179
|
return preverify_ok;
|
141
180
|
}
|
142
181
|
|
143
|
-
|
144
|
-
|
182
|
+
static VALUE
|
183
|
+
sslctx_alloc(VALUE klass) {
|
184
|
+
SSL_CTX *ctx;
|
185
|
+
long mode = 0 |
|
186
|
+
SSL_MODE_ENABLE_PARTIAL_WRITE |
|
187
|
+
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |
|
188
|
+
SSL_MODE_RELEASE_BUFFERS;
|
189
|
+
|
190
|
+
#ifdef HAVE_TLS_SERVER_METHOD
|
191
|
+
ctx = SSL_CTX_new(TLS_method());
|
192
|
+
// printf("\nctx using TLS_method security_level %d\n", SSL_CTX_get_security_level(ctx));
|
193
|
+
#else
|
194
|
+
ctx = SSL_CTX_new(SSLv23_method());
|
195
|
+
#endif
|
196
|
+
if (!ctx) {
|
197
|
+
rb_raise(eError, "SSL_CTX_new");
|
198
|
+
}
|
199
|
+
SSL_CTX_set_mode(ctx, mode);
|
200
|
+
|
201
|
+
return TypedData_Wrap_Struct(klass, &sslctx_type, ctx);
|
202
|
+
}
|
203
|
+
|
204
|
+
VALUE
|
205
|
+
sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
|
145
206
|
SSL_CTX* ctx;
|
146
|
-
SSL* ssl;
|
147
|
-
int min, ssl_options;
|
148
207
|
|
149
|
-
|
208
|
+
#ifdef HAVE_SSL_CTX_SET_MIN_PROTO_VERSION
|
209
|
+
int min;
|
210
|
+
#endif
|
211
|
+
int ssl_options;
|
212
|
+
VALUE key, cert, ca, verify_mode, ssl_cipher_filter, no_tlsv1, no_tlsv1_1,
|
213
|
+
verification_flags, session_id_bytes, cert_pem, key_pem;
|
214
|
+
#ifndef HAVE_SSL_GET1_PEER_CERTIFICATE
|
215
|
+
DH *dh;
|
216
|
+
#endif
|
217
|
+
BIO *bio;
|
218
|
+
X509 *x509;
|
219
|
+
EVP_PKEY *pkey;
|
150
220
|
|
151
|
-
|
152
|
-
|
221
|
+
#if OPENSSL_VERSION_NUMBER < 0x10002000L
|
222
|
+
EC_KEY *ecdh;
|
223
|
+
#endif
|
153
224
|
|
154
|
-
|
225
|
+
TypedData_Get_Struct(self, SSL_CTX, &sslctx_type, ctx);
|
155
226
|
|
156
|
-
|
157
|
-
VALUE cert = rb_funcall(mini_ssl_ctx, sym_cert, 0);
|
227
|
+
key = rb_funcall(mini_ssl_ctx, rb_intern_const("key"), 0);
|
158
228
|
|
159
|
-
|
229
|
+
cert = rb_funcall(mini_ssl_ctx, rb_intern_const("cert"), 0);
|
160
230
|
|
161
|
-
|
162
|
-
VALUE ca = rb_funcall(mini_ssl_ctx, sym_ca, 0);
|
231
|
+
ca = rb_funcall(mini_ssl_ctx, rb_intern_const("ca"), 0);
|
163
232
|
|
164
|
-
|
165
|
-
VALUE verify_mode = rb_funcall(mini_ssl_ctx, sym_verify_mode, 0);
|
233
|
+
cert_pem = rb_funcall(mini_ssl_ctx, rb_intern_const("cert_pem"), 0);
|
166
234
|
|
167
|
-
|
168
|
-
VALUE ssl_cipher_filter = rb_funcall(mini_ssl_ctx, sym_ssl_cipher_filter, 0);
|
235
|
+
key_pem = rb_funcall(mini_ssl_ctx, rb_intern_const("key_pem"), 0);
|
169
236
|
|
170
|
-
|
171
|
-
VALUE no_tlsv1 = rb_funcall(mini_ssl_ctx, sym_no_tlsv1, 0);
|
237
|
+
verify_mode = rb_funcall(mini_ssl_ctx, rb_intern_const("verify_mode"), 0);
|
172
238
|
|
173
|
-
|
174
|
-
VALUE no_tlsv1_1 = rb_funcall(mini_ssl_ctx, sym_no_tlsv1_1, 0);
|
239
|
+
ssl_cipher_filter = rb_funcall(mini_ssl_ctx, rb_intern_const("ssl_cipher_filter"), 0);
|
175
240
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
241
|
+
no_tlsv1 = rb_funcall(mini_ssl_ctx, rb_intern_const("no_tlsv1"), 0);
|
242
|
+
|
243
|
+
no_tlsv1_1 = rb_funcall(mini_ssl_ctx, rb_intern_const("no_tlsv1_1"), 0);
|
244
|
+
|
245
|
+
if (!NIL_P(cert)) {
|
246
|
+
StringValue(cert);
|
247
|
+
SSL_CTX_use_certificate_chain_file(ctx, RSTRING_PTR(cert));
|
248
|
+
}
|
249
|
+
|
250
|
+
if (!NIL_P(key)) {
|
251
|
+
StringValue(key);
|
252
|
+
SSL_CTX_use_PrivateKey_file(ctx, RSTRING_PTR(key), SSL_FILETYPE_PEM);
|
253
|
+
}
|
254
|
+
|
255
|
+
if (!NIL_P(cert_pem)) {
|
256
|
+
bio = BIO_new(BIO_s_mem());
|
257
|
+
BIO_puts(bio, RSTRING_PTR(cert_pem));
|
258
|
+
x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
|
259
|
+
|
260
|
+
SSL_CTX_use_certificate(ctx, x509);
|
261
|
+
}
|
262
|
+
|
263
|
+
if (!NIL_P(key_pem)) {
|
264
|
+
bio = BIO_new(BIO_s_mem());
|
265
|
+
BIO_puts(bio, RSTRING_PTR(key_pem));
|
266
|
+
pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
|
267
|
+
|
268
|
+
SSL_CTX_use_PrivateKey(ctx, pkey);
|
269
|
+
}
|
182
270
|
|
183
|
-
|
184
|
-
|
271
|
+
verification_flags = rb_funcall(mini_ssl_ctx, rb_intern_const("verification_flags"), 0);
|
272
|
+
|
273
|
+
if (!NIL_P(verification_flags)) {
|
274
|
+
X509_VERIFY_PARAM *param = SSL_CTX_get0_param(ctx);
|
275
|
+
X509_VERIFY_PARAM_set_flags(param, NUM2INT(verification_flags));
|
276
|
+
SSL_CTX_set1_param(ctx, param);
|
277
|
+
}
|
185
278
|
|
186
279
|
if (!NIL_P(ca)) {
|
187
280
|
StringValue(ca);
|
@@ -228,35 +321,66 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
|
|
228
321
|
SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL@STRENGTH");
|
229
322
|
}
|
230
323
|
|
231
|
-
DH *dh = get_dh1024();
|
232
|
-
SSL_CTX_set_tmp_dh(ctx, dh);
|
233
|
-
|
234
324
|
#if OPENSSL_VERSION_NUMBER < 0x10002000L
|
235
325
|
// Remove this case if OpenSSL 1.0.1 (now EOL) support is no
|
236
326
|
// longer needed.
|
237
|
-
|
327
|
+
ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
|
238
328
|
if (ecdh) {
|
239
329
|
SSL_CTX_set_tmp_ecdh(ctx, ecdh);
|
240
330
|
EC_KEY_free(ecdh);
|
241
331
|
}
|
242
332
|
#elif OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
|
243
|
-
// Prior to OpenSSL 1.1.0, servers must manually enable server-side ECDH
|
244
|
-
// negotiation.
|
245
333
|
SSL_CTX_set_ecdh_auto(ctx, 1);
|
246
334
|
#endif
|
247
335
|
|
248
|
-
ssl = SSL_new(ctx);
|
249
|
-
conn->ssl = ssl;
|
250
|
-
SSL_set_app_data(ssl, NULL);
|
251
|
-
|
252
336
|
if (NIL_P(verify_mode)) {
|
253
|
-
/*
|
337
|
+
/* SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL); */
|
254
338
|
} else {
|
255
|
-
|
339
|
+
SSL_CTX_set_verify(ctx, NUM2INT(verify_mode), engine_verify_callback);
|
256
340
|
}
|
257
341
|
|
258
|
-
|
342
|
+
// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
343
|
+
session_id_bytes = rb_funcall(
|
344
|
+
#ifdef HAVE_RANDOM_BYTES
|
345
|
+
rb_cRandom,
|
346
|
+
#else
|
347
|
+
rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
|
348
|
+
#endif
|
349
|
+
rb_intern_const("bytes"),
|
350
|
+
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));
|
351
|
+
|
352
|
+
SSL_CTX_set_session_id_context(ctx,
|
353
|
+
(unsigned char *) RSTRING_PTR(session_id_bytes),
|
354
|
+
SSL_MAX_SSL_SESSION_ID_LENGTH);
|
355
|
+
|
356
|
+
// printf("\ninitialize end security_level %d\n", SSL_CTX_get_security_level(ctx));
|
357
|
+
|
358
|
+
#ifdef HAVE_SSL_GET1_PEER_CERTIFICATE
|
359
|
+
// https://www.openssl.org/docs/man3.0/man3/SSL_CTX_set_dh_auto.html
|
360
|
+
SSL_CTX_set_dh_auto(ctx, 1);
|
361
|
+
#else
|
362
|
+
dh = get_dh2048();
|
363
|
+
SSL_CTX_set_tmp_dh(ctx, dh);
|
364
|
+
#endif
|
365
|
+
|
366
|
+
rb_obj_freeze(self);
|
367
|
+
return self;
|
368
|
+
}
|
369
|
+
|
370
|
+
VALUE engine_init_server(VALUE self, VALUE sslctx) {
|
371
|
+
ms_conn* conn;
|
372
|
+
VALUE obj;
|
373
|
+
SSL_CTX* ctx;
|
374
|
+
SSL* ssl;
|
259
375
|
|
376
|
+
conn = engine_alloc(self, &obj);
|
377
|
+
|
378
|
+
TypedData_Get_Struct(sslctx, SSL_CTX, &sslctx_type, ctx);
|
379
|
+
|
380
|
+
ssl = SSL_new(ctx);
|
381
|
+
conn->ssl = ssl;
|
382
|
+
SSL_set_app_data(ssl, NULL);
|
383
|
+
SSL_set_bio(ssl, conn->read, conn->write);
|
260
384
|
SSL_set_accept_state(ssl);
|
261
385
|
return obj;
|
262
386
|
}
|
@@ -296,7 +420,7 @@ VALUE engine_inject(VALUE self, VALUE str) {
|
|
296
420
|
return INT2FIX(used);
|
297
421
|
}
|
298
422
|
|
299
|
-
|
423
|
+
NORETURN(void raise_error(SSL* ssl, int result));
|
300
424
|
|
301
425
|
void raise_error(SSL* ssl, int result) {
|
302
426
|
char buf[512];
|
@@ -320,8 +444,7 @@ void raise_error(SSL* ssl, int result) {
|
|
320
444
|
} else {
|
321
445
|
err = (int) ERR_get_error();
|
322
446
|
ERR_error_string_n(err, buf, sizeof(buf));
|
323
|
-
|
324
|
-
snprintf(msg, sizeof(msg), "OpenSSL error: %s - %d", buf, errexp);
|
447
|
+
snprintf(msg, sizeof(msg), "OpenSSL error: %s - %d", buf, err & mask);
|
325
448
|
}
|
326
449
|
} else {
|
327
450
|
snprintf(msg, sizeof(msg), "Unknown OpenSSL error: %d", ssl_err);
|
@@ -385,7 +508,9 @@ VALUE engine_extract(VALUE self) {
|
|
385
508
|
ms_conn* conn;
|
386
509
|
int bytes;
|
387
510
|
size_t pending;
|
388
|
-
|
511
|
+
// https://www.openssl.org/docs/manmaster/man3/BIO_f_buffer.html
|
512
|
+
// crypto/bio/bf_buff.c DEFAULT_BUFFER_SIZE
|
513
|
+
char buf[4096];
|
389
514
|
|
390
515
|
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
|
391
516
|
|
@@ -436,7 +561,11 @@ VALUE engine_peercert(VALUE self) {
|
|
436
561
|
|
437
562
|
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
|
438
563
|
|
564
|
+
#ifdef HAVE_SSL_GET1_PEER_CERTIFICATE
|
565
|
+
cert = SSL_get1_peer_certificate(conn->ssl);
|
566
|
+
#else
|
439
567
|
cert = SSL_get_peer_certificate(conn->ssl);
|
568
|
+
#endif
|
440
569
|
if(!cert) {
|
441
570
|
/*
|
442
571
|
* See if there was a failed certificate associated with this client.
|
@@ -480,7 +609,7 @@ VALUE noop(VALUE self) {
|
|
480
609
|
}
|
481
610
|
|
482
611
|
void Init_mini_ssl(VALUE puma) {
|
483
|
-
VALUE mod, eng;
|
612
|
+
VALUE mod, eng, sslctx;
|
484
613
|
|
485
614
|
/* Fake operation for documentation (RDoc, YARD) */
|
486
615
|
#if 0 == 1
|
@@ -493,7 +622,15 @@ void Init_mini_ssl(VALUE puma) {
|
|
493
622
|
ERR_load_crypto_strings();
|
494
623
|
|
495
624
|
mod = rb_define_module_under(puma, "MiniSSL");
|
625
|
+
|
496
626
|
eng = rb_define_class_under(mod, "Engine", rb_cObject);
|
627
|
+
rb_undef_alloc_func(eng);
|
628
|
+
|
629
|
+
sslctx = rb_define_class_under(mod, "SSLContext", rb_cObject);
|
630
|
+
rb_define_alloc_func(sslctx, sslctx_alloc);
|
631
|
+
rb_define_method(sslctx, "initialize", sslctx_initialize, 1);
|
632
|
+
rb_undef_method(sslctx, "initialize_copy");
|
633
|
+
|
497
634
|
|
498
635
|
// OpenSSL Build / Runtime/Load versions
|
499
636
|
|
@@ -552,9 +689,10 @@ void Init_mini_ssl(VALUE puma) {
|
|
552
689
|
|
553
690
|
#else
|
554
691
|
|
692
|
+
NORETURN(VALUE raise_error(VALUE self));
|
693
|
+
|
555
694
|
VALUE raise_error(VALUE self) {
|
556
695
|
rb_raise(rb_eStandardError, "SSL not available in this build");
|
557
|
-
return Qnil;
|
558
696
|
}
|
559
697
|
|
560
698
|
void Init_mini_ssl(VALUE puma) {
|
File without changes
|
File without changes
|
@@ -34,9 +34,9 @@ private static short[] init__puma_parser_key_offsets_0()
|
|
34
34
|
{
|
35
35
|
return new short [] {
|
36
36
|
0, 0, 8, 17, 27, 29, 30, 31, 32, 33, 34, 36,
|
37
|
-
39, 41, 44, 45, 61, 62, 78,
|
38
|
-
|
39
|
-
|
37
|
+
39, 41, 44, 45, 61, 62, 78, 85, 91, 99, 107, 117,
|
38
|
+
125, 134, 142, 150, 159, 168, 177, 186, 195, 204, 213, 222,
|
39
|
+
231, 240, 249, 258, 267, 276, 285, 294, 303, 312, 313
|
40
40
|
};
|
41
41
|
}
|
42
42
|
|
@@ -52,26 +52,27 @@ private static char[] init__puma_parser_trans_keys_0()
|
|
52
52
|
46, 48, 57, 48, 57, 13, 48, 57, 10, 13, 33, 124,
|
53
53
|
126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94,
|
54
54
|
122, 10, 33, 58, 124, 126, 35, 39, 42, 43, 45, 46,
|
55
|
-
48, 57, 65, 90, 94, 122, 13, 32,
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
63
|
-
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
64
|
-
46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
65
|
-
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
66
|
-
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
67
|
-
46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
68
|
-
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
69
|
-
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
70
|
-
46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
71
|
-
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
72
|
-
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
73
|
-
46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
74
|
-
65, 90, 32,
|
55
|
+
48, 57, 65, 90, 94, 122, 13, 32, 127, 0, 8, 10,
|
56
|
+
31, 13, 127, 0, 8, 10, 31, 32, 60, 62, 127, 0,
|
57
|
+
31, 34, 35, 32, 60, 62, 127, 0, 31, 34, 35, 43,
|
58
|
+
58, 45, 46, 48, 57, 65, 90, 97, 122, 32, 34, 35,
|
59
|
+
60, 62, 127, 0, 31, 32, 34, 35, 60, 62, 63, 127,
|
60
|
+
0, 31, 32, 34, 35, 60, 62, 127, 0, 31, 32, 34,
|
61
|
+
35, 60, 62, 127, 0, 31, 32, 36, 95, 45, 46, 48,
|
62
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
63
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
64
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
65
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
66
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
67
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
68
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
69
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
70
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
71
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
72
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
73
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
74
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
75
|
+
32, 0
|
75
76
|
};
|
76
77
|
}
|
77
78
|
|
@@ -82,7 +83,7 @@ private static byte[] init__puma_parser_single_lengths_0()
|
|
82
83
|
{
|
83
84
|
return new byte [] {
|
84
85
|
0, 2, 3, 4, 2, 1, 1, 1, 1, 1, 0, 1,
|
85
|
-
0, 1, 1, 4, 1, 4,
|
86
|
+
0, 1, 1, 4, 1, 4, 3, 2, 4, 4, 2, 6,
|
86
87
|
7, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
87
88
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0
|
88
89
|
};
|
@@ -95,7 +96,7 @@ private static byte[] init__puma_parser_range_lengths_0()
|
|
95
96
|
{
|
96
97
|
return new byte [] {
|
97
98
|
0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 1,
|
98
|
-
1, 1, 0, 6, 0, 6,
|
99
|
+
1, 1, 0, 6, 0, 6, 2, 2, 2, 2, 4, 1,
|
99
100
|
1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
100
101
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0
|
101
102
|
};
|
@@ -108,9 +109,9 @@ private static short[] init__puma_parser_index_offsets_0()
|
|
108
109
|
{
|
109
110
|
return new short [] {
|
110
111
|
0, 0, 6, 13, 21, 24, 26, 28, 30, 32, 34, 36,
|
111
|
-
39, 41, 44, 46, 57, 59, 70,
|
112
|
-
|
113
|
-
|
112
|
+
39, 41, 44, 46, 57, 59, 70, 76, 81, 88, 95, 102,
|
113
|
+
110, 119, 127, 135, 142, 149, 156, 163, 170, 177, 184, 191,
|
114
|
+
198, 205, 212, 219, 226, 233, 240, 247, 254, 261, 263
|
114
115
|
};
|
115
116
|
}
|
116
117
|
|
@@ -126,22 +127,23 @@ private static byte[] init__puma_parser_indicies_0()
|
|
126
127
|
16, 15, 1, 17, 1, 18, 17, 1, 19, 1, 20, 21,
|
127
128
|
21, 21, 21, 21, 21, 21, 21, 21, 1, 22, 1, 23,
|
128
129
|
24, 23, 23, 23, 23, 23, 23, 23, 23, 1, 26, 27,
|
129
|
-
|
130
|
-
1, 1, 1, 1,
|
131
|
-
|
132
|
-
1,
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
63, 63, 1, 2, 1, 1,
|
130
|
+
1, 1, 1, 25, 29, 1, 1, 1, 28, 30, 1, 1,
|
131
|
+
1, 1, 1, 31, 32, 1, 1, 1, 1, 1, 33, 34,
|
132
|
+
35, 34, 34, 34, 34, 1, 8, 1, 9, 1, 1, 1,
|
133
|
+
1, 35, 36, 1, 38, 1, 1, 39, 1, 1, 37, 40,
|
134
|
+
1, 42, 1, 1, 1, 1, 41, 43, 1, 45, 1, 1,
|
135
|
+
1, 1, 44, 2, 46, 46, 46, 46, 46, 1, 2, 47,
|
136
|
+
47, 47, 47, 47, 1, 2, 48, 48, 48, 48, 48, 1,
|
137
|
+
2, 49, 49, 49, 49, 49, 1, 2, 50, 50, 50, 50,
|
138
|
+
50, 1, 2, 51, 51, 51, 51, 51, 1, 2, 52, 52,
|
139
|
+
52, 52, 52, 1, 2, 53, 53, 53, 53, 53, 1, 2,
|
140
|
+
54, 54, 54, 54, 54, 1, 2, 55, 55, 55, 55, 55,
|
141
|
+
1, 2, 56, 56, 56, 56, 56, 1, 2, 57, 57, 57,
|
142
|
+
57, 57, 1, 2, 58, 58, 58, 58, 58, 1, 2, 59,
|
143
|
+
59, 59, 59, 59, 1, 2, 60, 60, 60, 60, 60, 1,
|
144
|
+
2, 61, 61, 61, 61, 61, 1, 2, 62, 62, 62, 62,
|
145
|
+
62, 1, 2, 63, 63, 63, 63, 63, 1, 2, 1, 1,
|
146
|
+
0
|
145
147
|
};
|
146
148
|
}
|
147
149
|
|
@@ -182,8 +184,6 @@ static final int puma_parser_start = 1;
|
|
182
184
|
static final int puma_parser_first_final = 46;
|
183
185
|
static final int puma_parser_error = 0;
|
184
186
|
|
185
|
-
static final int puma_parser_en_main = 1;
|
186
|
-
|
187
187
|
|
188
188
|
// line 62 "ext/puma_http11/http11_parser.java.rl"
|
189
189
|
|
@@ -212,12 +212,12 @@ static final int puma_parser_en_main = 1;
|
|
212
212
|
cs = 0;
|
213
213
|
|
214
214
|
|
215
|
-
// line
|
215
|
+
// line 216 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
216
216
|
{
|
217
217
|
cs = puma_parser_start;
|
218
218
|
}
|
219
219
|
|
220
|
-
// line
|
220
|
+
// line 88 "ext/puma_http11/http11_parser.java.rl"
|
221
221
|
|
222
222
|
body_start = 0;
|
223
223
|
content_len = 0;
|
@@ -244,7 +244,7 @@ static final int puma_parser_en_main = 1;
|
|
244
244
|
parser.buffer = buffer;
|
245
245
|
|
246
246
|
|
247
|
-
// line
|
247
|
+
// line 248 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
248
248
|
{
|
249
249
|
int _klen;
|
250
250
|
int _trans = 0;
|
@@ -400,7 +400,7 @@ case 1:
|
|
400
400
|
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
401
401
|
}
|
402
402
|
break;
|
403
|
-
// line
|
403
|
+
// line 404 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
404
404
|
}
|
405
405
|
}
|
406
406
|
}
|
@@ -420,7 +420,7 @@ case 5:
|
|
420
420
|
break; }
|
421
421
|
}
|
422
422
|
|
423
|
-
// line
|
423
|
+
// line 114 "ext/puma_http11/http11_parser.java.rl"
|
424
424
|
|
425
425
|
parser.cs = cs;
|
426
426
|
parser.nread += (p - off);
|