Class: Plum::Rack::TLSListener

Inherits:
BaseListener show all
Defined in:
lib/plum/rack/listener.rb

Instance Method Summary collapse

Methods inherited from BaseListener

#method_missing, #stop

Constructor Details

#initialize(lc) ⇒ TLSListener

Returns a new instance of TLSListener.


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/plum/rack/listener.rb', line 33

def initialize(lc)
  cert, key = lc[:certificate], lc[:certificate_key]
  unless cert && key
    puts "WARNING: using dummy certificate"
    cert, key = dummy_key
  end

  ctx = OpenSSL::SSL::SSLContext.new
  ctx.ssl_version = :TLSv1_2
  ctx.alpn_select_cb = -> protocols {
    raise "Client does not support HTTP/2: #{protocols}" unless protocols.include?("h2")
    "h2"
  }
  ctx.tmp_ecdh_callback = -> (sock, ise, keyl) { OpenSSL::PKey::EC.new("prime256v1") }
  ctx.cert = OpenSSL::X509::Certificate.new(cert)
  ctx.key = OpenSSL::PKey::RSA.new(key)
  tcp_server = ::TCPServer.new(lc[:hostname], lc[:port])
  @server = OpenSSL::SSL::SSLServer.new(tcp_server, ctx)
  @server.start_immediately = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plum::Rack::BaseListener

Instance Method Details

#plum(sock) ⇒ Object


58
59
60
# File 'lib/plum/rack/listener.rb', line 58

def plum(sock)
  ::Plum::HTTPSServerConnection.new(sock)
end

#to_ioObject


54
55
56
# File 'lib/plum/rack/listener.rb', line 54

def to_io
  @server.to_io
end