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

Use OpenSSL DTLS_method & TLS_server_method when available #1832

Merged
merged 4 commits into from Jul 8, 2019
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
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -35,6 +35,9 @@ rvm:
matrix:
fast_finish: true
include:
- rvm: 2.2
dist: trusty
env: NOTES="Trusty OpenSSL 1.0.1"
- rvm: ruby-head
env: RUBYOPT="--jit"
- rvm: 2.4.6
Expand Down
4 changes: 3 additions & 1 deletion History.md
@@ -1,7 +1,9 @@
## Master

x features
x bugfixes

* ? bugfixes
* Add extconf tests for DTLS_method & TLS_server_method, use in minissl.rb. (#1832)

## 4.0.0 / 2019-06-25

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -3,7 +3,7 @@ require "rake/testtask"
require "rake/extensiontask"
require "rake/javaextensiontask"
require "rubocop/rake_task"
require 'puma/detect'
require_relative 'lib/puma/detect'
require 'rubygems/package_task'
require 'bundler/gem_tasks'

Expand Down
8 changes: 8 additions & 0 deletions ext/puma_http11/extconf.rb
Expand Up @@ -9,6 +9,14 @@
%w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}

have_header "openssl/bio.h"

# below is yes for 1.0.2 & later
have_func "DTLS_method" , "openssl/ssl.h"

# below are yes for 1.1.0 & later, may need to check func rather than macro
# with versions after 1.1.1
have_func "TLS_server_method" , "openssl/ssl.h"
have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
end
end

Expand Down
10 changes: 8 additions & 2 deletions ext/puma_http11/mini_ssl.c
Expand Up @@ -168,8 +168,11 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
ID sym_no_tlsv1 = rb_intern("no_tlsv1");
VALUE no_tlsv1 = rb_funcall(mini_ssl_ctx, sym_no_tlsv1, 0);


#ifdef HAVE_TLS_SERVER_METHOD
ctx = SSL_CTX_new(TLS_server_method());
#else
ctx = SSL_CTX_new(SSLv23_server_method());
#endif
conn->ctx = ctx;

SSL_CTX_use_certificate_chain_file(ctx, RSTRING_PTR(cert));
Expand Down Expand Up @@ -232,8 +235,11 @@ VALUE engine_init_server(VALUE self, VALUE mini_ssl_ctx) {
VALUE engine_init_client(VALUE klass) {
VALUE obj;
ms_conn* conn = engine_alloc(klass, &obj);

#ifdef HAVE_DTLS_METHOD
conn->ctx = SSL_CTX_new(DTLS_method());
#else
conn->ctx = SSL_CTX_new(DTLSv1_method());
#endif
conn->ssl = SSL_new(conn->ctx);
SSL_set_app_data(conn->ssl, NULL);
SSL_set_verify(conn->ssl, SSL_VERIFY_NONE, NULL);
Expand Down