How do I configure WEBrick to use an intermediate certificate with HTTPS?

前端 未结 2 1077
悲哀的现实
悲哀的现实 2021-01-11 21:01

I am currently using the following options in my Rails app to enable HTTPS with WEBrick:

{
    :Port => 3000,
    :environment => (ENV[\'RAILS_ENV\'] |         


        
相关标签:
2条回答
  • 2021-01-11 21:24

    If you are using rails 3, then modify the script/rails file as

    #!/usr/bin/env ruby
    # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
    require 'rubygems' # if ruby 1.8.7 
    require 'rails/commands/server'
    require 'rack'
    require 'webrick'
    require 'webrick/https'
    
    module Rails
        class Server < ::Rack::Server
            def default_options
                super.merge({
                    :Port => 3000,
                    :environment => (ENV['RAILS_ENV'] || "development").dup,
                    :daemonize => false,
                    :debugger => false,
                    :pid => File.expand_path("tmp/pids/server.pid"),
                    :config => File.expand_path("config.ru"),
                    :SSLEnable => true,
                    :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
                    :SSLPrivateKey => OpenSSL::PKey::RSA.new(
                           File.open("/key/vhost1.key").read),
                    :SSLCertificate => OpenSSL::X509::Certificate.new(
                           File.open("/crt/vhost1.crt").read),
                    :SSLCertName => [["CN", WEBrick::Utils::getservername]],
                })
            end
        end
    end
    
    APP_PATH = File.expand_path('../../config/application',  __FILE__)
    require File.expand_path('../../config/boot',  __FILE__)
    require 'rails/commands'
    

    The above code was modified from the example in Configuring WEBrick to use SSL in Rails 3. This worked for me.

    0 讨论(0)
  • 2021-01-11 21:29

    I managed to find an answer after an extra hour of googling for keywords. Here is the option to define an intermediate certificate:

    :SSLExtraChainCert => [
        OpenSSL::X509::Certificate.new(
          File.open("certificates/intermediate.crt").read)]
    

    Note that the option requires an Array object, allowing to you include multiple certificates if needed.

    0 讨论(0)
提交回复
热议问题