1 # -*- encoding: binary -*-
3 # This module is included in Unicorn::Configurator
6 module Unicorn::SSLConfigurator
9 before = @set[:listeners].dup
10 opts = @set[:ssl_opts] = {}
12 (@set[:listeners] - before).each do |address|
13 (@set[:listener_opts][address] ||= {})[:ssl_opts] = opts
16 @set.delete(:ssl_opts)
19 def ssl_certificate(file)
20 ssl_set(:ssl_certificate, file)
23 def ssl_certificate_key(file)
24 ssl_set(:ssl_certificate_key, file)
27 def ssl_client_certificate(file)
28 ssl_set(:ssl_client_certificate, file)
32 ssl_set(:ssl_dhparam, file)
35 def ssl_ciphers(openssl_cipherlist_spec)
36 ssl_set(:ssl_ciphers, openssl_cipherlist_spec)
40 ssl_set(:ssl_crl, file)
43 def ssl_prefer_server_ciphers(bool)
44 ssl_set(:ssl_prefer_server_ciphers, check_bool(bool))
47 def ssl_protocols(list)
48 ssl_set(:ssl_protocols, list)
51 def ssl_verify_client(on_off_optional)
52 ssl_set(:ssl_verify_client, on_off_optional)
55 def ssl_session_timeout(seconds)
56 ssl_set(:ssl_session_timeout, seconds)
59 def ssl_verify_depth(depth)
60 ssl_set(:ssl_verify_depth, depth)
63 # Allows specifying an engine for OpenSSL to use. We have not been
64 # able to successfully test this feature due to a lack of hardware,
65 # Reports of success or patches to mongrel-unicorn@rubyforge.org is
66 # greatly appreciated.
67 def ssl_engine(engine)
68 ssl_warn_global(:ssl_engine)
71 OpenSSL::Engine.by_id(engine)
72 @set[:ssl_engine] = engine
75 def ssl_compression(bool)
76 # OpenSSL uses the SSL_OP_NO_COMPRESSION flag, Flipper follows suit
77 # with :ssl_no_compression, but we negate it to avoid exposing double
78 # negatives to the user.
79 ssl_set(:ssl_no_compression, check_bool(:ssl_compression, ! bool))
84 def ssl_warn_global(func) # :nodoc:
85 Hash === @set[:ssl_opts] or return
86 warn("`#{func}' affects all SSL contexts in this process, " \
87 "not just this block")
90 def ssl_set(key, value) # :nodoc:
93 raise ArgumentError, "#{key} must be called inside an `ssl' block"
97 def ssl_require! # :nodoc:
99 require "unicorn/ssl_client"
101 warn "install 'kgio-monkey' for SSL support"