Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minissl.c - Use Random.bytes if available #2642

Merged
merged 1 commit into from Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/puma_http11/extconf.rb
Expand Up @@ -25,6 +25,14 @@

have_func "X509_STORE_up_ref"
have_func("SSL_CTX_set_ecdh_auto(NULL, 0)", "openssl/ssl.h")

# Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
if Random.respond_to?(:bytes)
$defs.push("-DHAVE_RANDOM_BYTES")
puts "checking for Random.bytes... yes"
else
puts "checking for Random.bytes... no"
end
end
end

Expand Down
13 changes: 10 additions & 3 deletions ext/puma_http11/mini_ssl.c
Expand Up @@ -310,9 +310,16 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
SSL_CTX_set_verify(ctx, NUM2INT(verify_mode), engine_verify_callback);
}

session_id_bytes = rb_funcall(rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
rb_intern_const("bytes"),
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));
// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
session_id_bytes = rb_funcall(
#ifdef HAVE_RANDOM_BYTES
rb_cRandom,
#else
rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
#endif
rb_intern_const("bytes"),
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));

SSL_CTX_set_session_id_context(ctx,
(unsigned char *) RSTRING_PTR(session_id_bytes),
SSL_MAX_SSL_SESSION_ID_LENGTH);
Expand Down