Skip to content

Commit

Permalink
reuse ssl context
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reinsch committed Aug 6, 2014
1 parent 5dfb72e commit ef155d1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/capybara/proxy_server.rb
Expand Up @@ -63,8 +63,7 @@ def run(app, config)
def initialize(app, config)
super(config, WEBrick::Config::HTTP)
@rack_handler = Rack::Handler::WEBrick.new(self, app)
@self_signed_cert, @self_signed_cert_key =
WEBrick::Utils.create_self_signed_cert(512, [ [ "CN", "localhost" ] ], "Generated by Ruby/OpenSSL")
@ssl_context = generate_ssl_context
@ssl_server = SSLHandler.new(app, config)
end

Expand All @@ -76,7 +75,7 @@ def service(req, res)
res.status = WEBrick::HTTPStatus::RC_OK
res.send_response(ua)
req.parse(NullReader) rescue nil
ssl = OpenSSL::SSL::SSLSocket.new(ua, ssl_context)
ssl = OpenSSL::SSL::SSLSocket.new(ua, @ssl_context)
ssl.sync_close = true
ssl.accept
@ssl_server.run(ssl)
Expand All @@ -95,13 +94,13 @@ def service(req, res)

private

def ssl_context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = @self_signed_cert
ssl_context.key = @self_signed_cert_key
ssl_context.ssl_version = :SSLv23
ssl_context.session_id_context = OpenSSL::Digest::MD5.hexdigest($0)
ssl_context
def generate_ssl_context
OpenSSL::SSL::SSLContext.new('SSLv23_server').tap do |ssl_context|
self_signed_cert, self_signed_cert_key =
WEBrick::Utils.create_self_signed_cert(512, [ [ "CN", "localhost" ] ], "Generated by Ruby/OpenSSL")
ssl_context.cert = self_signed_cert
ssl_context.key = self_signed_cert_key
end
end
end
end
Expand Down

0 comments on commit ef155d1

Please sign in to comment.