From aeadf47170ad56abc38cc0bd267f25816fddfab6 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Wed, 25 Jan 2023 10:46:16 -0600 Subject: [PATCH 1/2] Conditionally add aliases for TLS 1.3 constants so that the module does not fail to load on/with older OpenSSL versions that do not support TLS 1.3. References #629, #646. Closes #652. --- lib/bunny/transport.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/bunny/transport.rb b/lib/bunny/transport.rb index 79440858..0c13a894 100644 --- a/lib/bunny/transport.rb +++ b/lib/bunny/transport.rb @@ -40,7 +40,17 @@ class Transport OpenSSL::SSL::TLS1_1_VERSION => OpenSSL::SSL::TLS1_1_VERSION, OpenSSL::SSL::TLS1_2_VERSION => OpenSSL::SSL::TLS1_2_VERSION, OpenSSL::SSL::TLS1_3_VERSION => OpenSSL::SSL::TLS1_3_VERSION - }.freeze + } + + # older OpenSSL versions won't support for TLS 1.3 and won't + # have this constant defined. + if defined?(OpenSSL::SSL::TLS1_3_VERSION) + TLS_VERSION_ALIASES["1.3"] = OpenSSL::SSL::TLS1_3_VERSION + TLS_VERSION_ALIASES[:TLSv1_3] = OpenSSL::SSL::TLS1_3_VERSION + TLS_VERSION_ALIASES[OpenSSL::SSL::TLS1_3_VERSION] = OpenSSL::SSL::TLS1_3_VERSION + end + + TLS_VERSION_ALIASES.freeze attr_reader :session, :host, :port, :socket, :connect_timeout, :read_timeout, :write_timeout, :disconnect_timeout attr_reader :tls_context, :verify_peer, :tls_ca_certificates, :tls_certificate_path, :tls_key_path From 07cb31476fdd2a33d0042a76ca4327ce9e09bb32 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Wed, 25 Jan 2023 12:24:12 -0600 Subject: [PATCH 2/2] Drop TLS 1.3 constants from the initial TLS_VERSION_ALIASES --- lib/bunny/transport.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/bunny/transport.rb b/lib/bunny/transport.rb index 0c13a894..d4d3f683 100644 --- a/lib/bunny/transport.rb +++ b/lib/bunny/transport.rb @@ -31,15 +31,12 @@ class Transport TLSv1: OpenSSL::SSL::TLS1_VERSION, TLSv1_1: OpenSSL::SSL::TLS1_1_VERSION, TLSv1_2: OpenSSL::SSL::TLS1_2_VERSION, - TLSv1_3: OpenSSL::SSL::TLS1_3_VERSION, "1.0": OpenSSL::SSL::TLS1_VERSION, "1.1": OpenSSL::SSL::TLS1_1_VERSION, "1.2": OpenSSL::SSL::TLS1_2_VERSION, - "1.3": OpenSSL::SSL::TLS1_3_VERSION, OpenSSL::SSL::TLS1_VERSION => OpenSSL::SSL::TLS1_VERSION, OpenSSL::SSL::TLS1_1_VERSION => OpenSSL::SSL::TLS1_1_VERSION, - OpenSSL::SSL::TLS1_2_VERSION => OpenSSL::SSL::TLS1_2_VERSION, - OpenSSL::SSL::TLS1_3_VERSION => OpenSSL::SSL::TLS1_3_VERSION + OpenSSL::SSL::TLS1_2_VERSION => OpenSSL::SSL::TLS1_2_VERSION } # older OpenSSL versions won't support for TLS 1.3 and won't