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

WIP: Ability to use ssl_min_version and/or ssl_max_version instead of ssl_method #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion lib/remote_syslog_sender/tcp_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def initialize(remote_hostname, remote_port, options = {})
@remote_hostname = remote_hostname
@remote_port = remote_port
@ssl_method = options[:ssl_method] || 'TLSv1_2'
@ssl_min_version = options[:ssl_min_version]
@ssl_max_version = options[:ssl_max_version]
@ca_file = options[:ca_file]
@verify_mode = options[:verify_mode]
@timeout = options[:timeout] || 600
Expand Down Expand Up @@ -63,7 +65,44 @@ def connect
end
if @tls
require 'openssl'
context = OpenSSL::SSL::SSLContext.new(@ssl_method)

min_max_available = true
tls_versions_map = {}
begin
tls_versions_map = {
TLSv1: OpenSSL::SSL::TLS1_VERSION,
TLSv1_1: OpenSSL::SSL::TLS1_1_VERSION,
TLSv1_2: OpenSSL::SSL::TLS1_2_VERSION
}
tls_versions_map[:'TLSv1_3'] = OpenSSL::SSL::TLS1_3_VERSION if defined?(OpenSSL::SSL::TLS1_3_VERSION)
rescue NameError
# ruby 2.4 doesn't have OpenSSL::SSL::TLSXXX constants and min_version=/max_version= methods
tls_versions_map = {
TLSv1: :'TLSv1',
TLSv1_1: :'TLSv1_1',
TLSv1_2: :'TLSv1_2',
}
min_max_available = false
end

context = OpenSSL::SSL::SSLContext.new()
if min_max_available
case
when @ssl_min_version && @ssl_max_version
context.min_version = @ssl_min_version
context.max_version = @ssl_max_version
when (!@ssl_min_version && @ssl_max_version) || (@ssl_min_version && !@ssl_max_version)
raise "Both :ssl_min_version and :ssl_max_version must be set if one is"
when !@ssl_min_version && !@ssl_max_version
# Keep the current behaviour
context.ssl_version = METHODS_MAP[@ssl_method] || @ssl_method
else
context.min_version = tls_versions_map[@ssl_min_version] || @ssl_min_version
context.max_version = tls_versions_map[@ssl_max_version] || @ssl_max_version
end
else
context.ssl_version = METHODS_MAP[@ssl_method] || @ssl_method
end
context.ca_file = @ca_file if @ca_file
context.verify_mode = @verify_mode if @verify_mode

Expand Down