1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Merge pull request #1689 from michaelherold/allow-ca-to-be-set-in-bind-dsl

Allow mutual TLS CA to be set using `ssl_bind` DSL
This commit is contained in:
Evan Phoenix 2019-03-11 16:39:52 -07:00 committed by GitHub
commit 6568aaeaf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View file

@ -296,13 +296,14 @@ module Puma
def ssl_bind(host, port, opts)
verify = opts.fetch(:verify_mode, 'none')
no_tlsv1 = opts.fetch(:no_tlsv1, 'false')
ca_additions = "&ca=#{opts[:ca]}" if ['peer', 'force_peer'].include?(verify)
if defined?(JRUBY_VERSION)
keystore_additions = "keystore=#{opts[:keystore]}&keystore-pass=#{opts[:keystore_pass]}"
bind "ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}&#{keystore_additions}&verify_mode=#{verify}&no_tlsv1=#{no_tlsv1}"
bind "ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}&#{keystore_additions}&verify_mode=#{verify}&no_tlsv1=#{no_tlsv1}#{ca_additions}"
else
ssl_cipher_filter = "&ssl_cipher_filter=#{opts[:ssl_cipher_filter]}" if opts[:ssl_cipher_filter]
bind "ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}#{ssl_cipher_filter}&verify_mode=#{verify}&no_tlsv1=#{no_tlsv1}"
bind "ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}#{ssl_cipher_filter}&verify_mode=#{verify}&no_tlsv1=#{no_tlsv1}#{ca_additions}"
end
end

View file

@ -1,4 +1,13 @@
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
ca = File.expand_path "../../examples/puma/client-certs/ca.crt", __FILE__
ssl_bind "0.0.0.0", 9292, :cert => cert, :key => key
ssl_bind "0.0.0.0", 9292, :cert => cert, :key => key, :verify_mode => "peer", :ca => ca
app do |env|
[200, {}, ["embedded app"]]
end
lowlevel_error_handler do |err|
[200, {}, ["error page"]]
end

View file

@ -30,6 +30,22 @@ class TestConfigFile < Minitest::Test
assert_equal [200, {}, ["embedded app"]], app.call({})
end
def test_ssl_configuration_from_DSL
conf = Puma::Configuration.new do |config|
config.load "test/config/ssl_config.rb"
end
conf.load
bind_configuration = conf.options.file_options[:binds].first
app = conf.app
assert bind_configuration =~ %r{ca=.*ca.crt}
assert bind_configuration =~ /verify_mode=peer/
assert_equal [200, {}, ["embedded app"]], app.call({})
end
def test_double_bind_port
port = (rand(10_000) + 30_000).to_s
with_env("PORT" => port) do