Class: BetterCap::Proxy::HTTP::SSL::Server
- Inherits:
-
Object
- Object
- BetterCap::Proxy::HTTP::SSL::Server
- Defined in:
- lib/bettercap/proxy/http/ssl/server.rb
Overview
Little utility class to handle SSLServer creation.
Instance Attribute Summary collapse
-
#authority ⇒ Object
readonly
The SSL certification authority.
-
#context ⇒ Object
readonly
Main SSLContext instance.
-
#io ⇒ Object
readonly
Socket I/O object.
Instance Method Summary collapse
-
#initialize(socket) ⇒ Server
constructor
Create an instance from the TCPSocket
socket
.
Constructor Details
#initialize(socket) ⇒ Server
Create an instance from the TCPSocket socket
.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bettercap/proxy/http/ssl/server.rb', line 29 def initialize( socket ) @authority = Authority.new( Context.get..proxies.proxy_pem_file ) @context = OpenSSL::SSL::SSLContext.new @context.cert = @authority.certificate @context.key = @authority.key # If the client supports SNI ( https://en.wikipedia.org/wiki/Server_Name_Indication ) # we'll receive the hostname it wants to connect to in this callback. # Use the CA we already have loaded ( or generated ) to sign a new # certificate at runtime with the correct 'Common Name' and create a new SSL # context with it, these are the steps: # # 1. Get hostname from SNI. # 2. Fetch upstream certificate from the real server. # 3. Resign it with our own CA. # 4. Create a new context with the new spoofed certificate. # 5. Profit ^_^ @context.servername_cb = proc { |sslsocket, hostname| Logger.debug "[#{'SSL'.green}] Server-Name-Indication for '#{hostname}'" ctx = OpenSSL::SSL::SSLContext.new ctx.cert = @authority.spoof( hostname ) ctx.key = @authority.key ctx } @io = OpenSSL::SSL::SSLServer.new( socket, @context ) end |
Instance Attribute Details
#authority ⇒ Object (readonly)
The SSL certification authority.
22 23 24 |
# File 'lib/bettercap/proxy/http/ssl/server.rb', line 22 def @authority end |
#context ⇒ Object (readonly)
Main SSLContext instance.
24 25 26 |
# File 'lib/bettercap/proxy/http/ssl/server.rb', line 24 def context @context end |
#io ⇒ Object (readonly)
Socket I/O object.
26 27 28 |
# File 'lib/bettercap/proxy/http/ssl/server.rb', line 26 def io @io end |