Class: Ritm::Proxy::SSLReverseProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/ritm/proxy/ssl_reverse_proxy.rb

Overview

SSL Intercept reverse proxy server. Supports interception of https request and responses It does man-in-the-middle with on-the-fly certificate signing using the given CA

Instance Method Summary collapse

Constructor Details

#initialize(port, ca, conf, request_interceptor: nil, response_interceptor: nil) ⇒ SSLReverseProxy

Creates a HTTPS server with the given settings

Parameters:

  • port (Fixnum)

    : TCP port to bind the service

  • ca (Ritm::CA)

    : The certificate authority used to sign fake server certificates

  • request_interceptor (Proc) (defaults to: nil)

    : If given, it will be invoked before proxying the request

  • response_interceptor (Proc) (defaults to: nil)

    : If give, it will be invoked before sending back the response



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ritm/proxy/ssl_reverse_proxy.rb', line 16

def initialize(port, ca, conf, request_interceptor: nil, response_interceptor: nil)
  @ca = ca
  default_vhost = 'localhost'
  @server = CertSigningHTTPSServer.new(Port: port,
                                       AccessLog: [],
                                       Logger: WEBrick::Log.new(File.open(File::NULL, 'w')),
                                       ca: ca,
                                       **vhost_settings(default_vhost))

  @server.mount '/', RequestInterceptorServlet, request_interceptor, response_interceptor, conf
end

Instance Method Details

#shutdownObject



34
35
36
# File 'lib/ritm/proxy/ssl_reverse_proxy.rb', line 34

def shutdown
  @server.shutdown
end

#start_asyncObject



28
29
30
31
32
# File 'lib/ritm/proxy/ssl_reverse_proxy.rb', line 28

def start_async
  trap(:TERM) { shutdown }
  trap(:INT) { shutdown }
  Thread.new { @server.start }
end