2012-01-11 47 views
10

我目前使用下列选项在我的Rails应用程序启用HTTPS与使用WEBrick:如何配置WEBrick以通过HTTPS使用中间证书?

{ 
    :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("certificates/https/key.pem").read), 
    :SSLCertificate => OpenSSL::X509::Certificate.new(
     File.open("certificates/https/cert.pem").read), 
    :SSLCertName => [["CN", WEBrick::Utils::getservername]] 
} 

我怎么会去指定中间证书?

+0

你不应该回答你自己的问题本身。你应该回答你自己的问题。 – 2012-04-21 13:39:12

+0

看来上面的代码来自[此博客文章](https://www.altamiracorp.com/blog/employee-posts/configuring-webrick-to-use-ssl),对吗? – 2014-04-17 06:21:04

+0

我想我是从WEBrick文档中提取的,这本身就是一个挑战。这是漂亮的锅炉板。虽然我不能评论@priteshj。 – 2014-04-17 15:45:47

回答

12

我在关键词的一个小时的搜索后设法找到了答案。我们首先要定义一个中间证书的选项:

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

注意,选择需要Array对象,允许你包含多个证书如果需要的话。

-1

如果使用导轨3,然后修改脚本/轨道文件作为

#!/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' 

上面的代码是从例如在Configuring WEBrick to use SSL in Rails 3修改。这对我有效。

+0

从.pem更改为.crt格式不会更改文件中存在的实际证书信息。我需要让WEBrick知道第三条信息,即中间证书。 – 2012-01-11 20:27:54

+0

你能分享你一直在编辑的script/rails文件吗?也是什么版本的红宝石和铁轨 – PriteshJ 2012-01-11 20:47:02

+0

我的问题是要求如何定义一个中间证书,而不是要求没有一个工作配置。 – 2012-01-11 20:55:59

相关问题