Class: BetterCap::Proxy::HTTP::SSL::Store
- Inherits:
-
Object
- Object
- BetterCap::Proxy::HTTP::SSL::Store
- Defined in:
- lib/bettercap/proxy/http/ssl/authority.rb
Overview
Used as an on-disk cache of server certificates.
Constant Summary collapse
- PATH =
The store path.
File.join( Dir.home, '.bettercap', 'certificates' )
Instance Method Summary collapse
-
#find(hostname, port) ⇒ Object
Find the
hostname
:port
certificate and return it. -
#initialize ⇒ Store
constructor
Create an instance of this class.
Constructor Details
#initialize ⇒ Store
Create an instance of this class.
45 46 47 48 49 50 51 52 53 |
# File 'lib/bettercap/proxy/http/ssl/authority.rb', line 45 def initialize unless File.directory?( Store::PATH ) Logger.info "[#{'SSL'.green}] Initializing certificates store '#{Store::PATH}' ..." FileUtils.mkdir_p( Store::PATH ) end @store = {} @lock = Mutex.new end |
Instance Method Details
#find(hostname, port) ⇒ Object
Find the hostname
:port
certificate and return it.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bettercap/proxy/http/ssl/authority.rb', line 56 def find( hostname, port ) key = Digest::SHA256.hexdigest( "#{hostname}_#{port}" ) @lock.synchronize { unless @store.has_key?(key) # Certificate not available in memory, search it in the store PATH. filename = File.join( Store::PATH, key ) s_cert = load_from_file( filename ) # Not available on disk too, fetch it from the server and save it. if s_cert.nil? Logger.info "[#{'SSL'.green}] Fetching certificate from #{hostname}:#{port} ..." s_cert = Fetcher.fetch( hostname, port ) save_to_file( s_cert, filename ) else Logger.debug "[#{'SSL'.green}] Loaded HTTPS certificate for '#{hostname}' from store." end @store[key] = s_cert end } @store[key] end |