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

Support localhost integration in ssl_bind #2711

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
19 changes: 17 additions & 2 deletions lib/puma/dsl.rb
Expand Up @@ -46,6 +46,14 @@ def self.ssl_bind_str(host, port, opts)
else ''
end

if ['127.0.0.1', 'localhost'].include?(host)
rodzyn marked this conversation as resolved.
Show resolved Hide resolved
key = "#{ENV["HOME"]}/.localhost/localhost.key"
cert = "#{ENV["HOME"]}/.localhost/localhost.crt"
rodzyn marked this conversation as resolved.
Show resolved Hide resolved
end

key = opts[:key] if opts[:key]
rodzyn marked this conversation as resolved.
Show resolved Hide resolved
cert = opts[:cert] if opts[:cert]

ca_additions = "&ca=#{opts[:ca]}" if ['peer', 'force_peer'].include?(verify)

if defined?(JRUBY_VERSION)
Expand All @@ -63,7 +71,7 @@ def self.ssl_bind_str(host, port, opts)
v_flags = (ary = opts[:verification_flags]) ?
"&verification_flags=#{Array(ary).join ','}" : nil

"ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}" \
"ssl://#{host}:#{port}?cert=#{cert}&key=#{key}" \
"#{ssl_cipher_filter}&verify_mode=#{verify}#{tls_str}#{ca_additions}#{v_flags}"
end
end
Expand Down Expand Up @@ -439,6 +447,12 @@ def threads(min, max)
# Instead of `bind 'ssl://127.0.0.1:9292?key=key_path&cert=cert_path'` you
# can also use the this method.
#
# When binding on localhost you don't need to specify cert and key - it will assume you are
# using localhost gem and will try to load appropriate files for you
#
# @example
# ssl_bind '127.0.0.1', '9292'
#
# @example
# ssl_bind '127.0.0.1', '9292', {
# cert: path_to_cert,
Expand All @@ -454,7 +468,8 @@ def threads(min, max)
# ssl_cipher_list: cipher_list, # optional
# verify_mode: verify_mode # default 'none'
# }
def ssl_bind(host, port, opts)
#
def ssl_bind(host, port, opts = {})
bind self.class.ssl_bind_str(host, port, opts)
end

Expand Down